--- id: sql-avg title: "SQL Avg" category: "Database" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SQL AVG() Function", "AVG 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", "avg", "aggregate"] raw_sources: ["https://www.w3schools.com/sql/sql_avg.asp"] applied_in: [] github_commit: "" --- # [[SQL Avg]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) AVG() returns a numeric column's mean, ignoring NULLs, and doubles as a comparison baseline when nested as a subquery in a WHERE clause. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **AVG() function** β€” returns the average value of a numeric column; ignores NULL values. [S1] - **Syntax** β€” `SELECT AVG(column_name) FROM table_name WHERE condition;`. [S1] - **AVG() with GROUP BY** β€” returns the average per group. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **AVG() as a subquery baseline** β€” `WHERE Price > (SELECT AVG(Price) FROM Products)` uses AVG() inside a subquery to compare each row against the overall average β€” a reusable pattern for "above/below average" filters. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic average: `SELECT AVG(Price) FROM Products;`. [S1] - With WHERE: `SELECT AVG(Price) FROM Products WHERE CategoryID = 1;`. [S1] - With alias: `SELECT AVG(Price) AS [average price] FROM Products;`. [S1] - Above-average filter via subquery: `SELECT * FROM Products WHERE Price > (SELECT AVG(Price) FROM Products);`. [S1] - With GROUP BY: `SELECT AVG(Price) AS AveragePrice, CategoryID FROM Products GROUP BY CategoryID;`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” "평균 이상/μ΄ν•˜" 필터링은 싀무 λ¦¬ν¬νŠΈμ—μ„œ ν”ν•œ νŒ¨ν„΄μ΄λ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Above-average filter using AVG() as subquery (SQL): ```sql SELECT * FROM Products WHERE Price > (SELECT AVG(Price) FROM Products); ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** 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 Group By]], [[SQL Where]] - **μ°Έμ‘° λ§₯락:** 평균값 계산 및 평균 λŒ€λΉ„ 비ꡐ ν•„ν„°λ§μ˜ κΈ°λ³Έ ν•¨μˆ˜. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” SQL AVG() Function β€” https://www.w3schools.com/sql/sql_avg.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "SQL AVG() Function" page (Astra wiki-curation, P-Reinforce v3.1 format).