--- id: sql-count title: "SQL Count" category: "Database" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SQL COUNT() Function", "COUNT function", "SQL 개수 μ„ΈκΈ°"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["sql", "database", "w3schools", "count", "aggregate"] raw_sources: ["https://www.w3schools.com/sql/sql_count.asp"] applied_in: [] github_commit: "" --- # [[SQL Count]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) COUNT() behaves differently depending on its argument β€” `COUNT(*)` counts all rows including NULLs, `COUNT(column)` counts non-null values, and `COUNT(DISTINCT column)` counts unique non-null values. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **COUNT() function** β€” returns the number of rows matching a specified criterion. [S1] - **Syntax** β€” `SELECT COUNT([DISTINCT] column_name | *) FROM table_name WHERE condition;`. [S1] - **`COUNT(*)`** β€” counts the total number of rows, including NULL values. [S1] - **`COUNT(column_name)`** β€” counts only non-null values in that column. [S1] - **`COUNT(DISTINCT column_name)`** β€” counts only unique, non-null values. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Argument choice changes semantics** β€” the three COUNT variants answer three different questions (total rows / filled-in rows / unique values), so picking the right one matters for correctness, not just style. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Total row count: `SELECT COUNT(*) FROM Products;`. [S1] - Non-null count for a column: `SELECT COUNT(ProductName) FROM Products;`. [S1] - Unique non-null count: `SELECT COUNT(DISTINCT Price) FROM Products;`. [S1] - With WHERE: `SELECT COUNT(ProductID) FROM Products WHERE Price > 20;`. [S1] - With alias: `SELECT COUNT(*) AS [Number of records] FROM Products;`. [S1] - With GROUP BY: `SELECT COUNT(*) AS [Number of records], CategoryID FROM Products GROUP BY CategoryID;`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” SELECT DISTINCT μ±•ν„°μ—μ„œ 이미 μ†Œκ°œλœ `COUNT(DISTINCT ...)` νŒ¨ν„΄μ΄ μ—¬κΈ°μ„œ μ •μ‹μœΌλ‘œ 닀뀄진닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Three COUNT variants (SQL): ```sql SELECT COUNT(*) FROM Products; -- all rows, incl. NULLs SELECT COUNT(ProductName) FROM Products; -- non-null values only SELECT COUNT(DISTINCT Price) FROM Products; -- unique non-null values ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[SQL Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[SQL Aggregate Functions]], [[SQL Select Distinct]], [[SQL Group By]] - **μ°Έμ‘° λ§₯락:** ν–‰ 개수λ₯Ό μ„ΈλŠ” λͺ¨λ“  리포트의 κΈ°λ³Έ ν•¨μˆ˜ β€” DISTINCT와 κ²°ν•©ν•΄ κ³ μœ κ°’ κ°œμˆ˜λ„ μ…€ 수 μžˆλ‹€. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” SQL COUNT() Function β€” https://www.w3schools.com/sql/sql_count.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "SQL COUNT() Function" page (Astra wiki-curation, P-Reinforce v3.1 format).