COUNT/SUM/AVG/MIN/MAX के Functions
Aggregate functions कई rows को एक single summary value में collapse करते हैं।
In this page:
Syntax
SELECT COUNT(*), SUM(column), AVG(column), MIN(column), MAX(column)
FROM table_name;
COUNT/SUM/AVG/MIN/MAX
COUNT rows count करता है, SUM add करता है, AVG average करता है, MIN और MAX extremes ढूंढते हैं। COUNT(*) को छोड़कर, ये NULLs ignore करते हैं। बिना GROUP BY के एक aggregate query एक row return करती है। PostgreSQL में integers का AVG एक decimal return करता है। COUNT(DISTINCT col) unique values count करता है।
Note:
COUNT(*) rows count करता है, COUNT(col) non-null values count करता है।
उदाहरण: COUNT/SUM/AVG/MIN/MAX
CREATE TABLE sales (id INTEGER PRIMARY KEY, item TEXT, qty INTEGER, price INTEGER);
INSERT INTO sales VALUES (1, 'pen', 5, 2), (2, 'book', 1, 12), (3, 'pen', 10, 2), (4, 'lamp', 2, 30);
SELECT COUNT(*) AS n, SUM(qty) AS total_qty, AVG(price) AS avg_price, MIN(price) AS cheapest, MAX(price) AS priciest FROM sales;
-- Output:
-- n | total_qty | avg_price | cheapest | priciest
-- 4 | 18 | 11.5 | 2 | 30
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- बिना GROUP BY के aggregated और plain columns mix करना
- यह भूल जाना कि NULLs ignore होते हैं
- यह उम्मीद करना कि integers का AVG एक integer होगा
चैप्टर सारांश
- COUNT SUM AVG MIN MAX jaise functions मिलते हैं
- Aggregates NULL ignore करते हैं
- COUNT(*) हर row count करता है
- बिना GROUP BY एक row
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: