SQL Count, Sum, Avg
Similar to the previous chapter, SUM, AVG, and COUNT functions are aggregate functions that return the sum of field, average value, and count. SUM and AVG can be applied only for numbers, and COUNT - for fields of any data type.
1SELECT AVG(price) FROM songs
If you want to find the number of records with some condition, you can apply COUNT to the *.
This query outputs the number of records with the release date in the 20th century:
12SELECT COUNT(*) FROM songs WHERE year <= 2000
Aggregate functions and Distinct
If you want to apply aggregate function to the unique values, write DISTINCT inside this function and before the column name:
1SELECT COUNT(DISTINCT song) FROM songs
Swipe to start coding
Now you have to write a query that helps you to calculate the total number of singers. Remember that some singers have two or more records in the table, but you have to pick these singers only once.
Lösung
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Zusammenfassen Sie dieses Kapitel
Code in file erklären
Erklären, warum file die Aufgabe nicht löst
Awesome!
Completion rate improved to 4.17
SQL Count, Sum, Avg
Swipe um das Menü anzuzeigen
Similar to the previous chapter, SUM, AVG, and COUNT functions are aggregate functions that return the sum of field, average value, and count. SUM and AVG can be applied only for numbers, and COUNT - for fields of any data type.
1SELECT AVG(price) FROM songs
If you want to find the number of records with some condition, you can apply COUNT to the *.
This query outputs the number of records with the release date in the 20th century:
12SELECT COUNT(*) FROM songs WHERE year <= 2000
Aggregate functions and Distinct
If you want to apply aggregate function to the unique values, write DISTINCT inside this function and before the column name:
1SELECT COUNT(DISTINCT song) FROM songs
Swipe to start coding
Now you have to write a query that helps you to calculate the total number of singers. Remember that some singers have two or more records in the table, but you have to pick these singers only once.
Lösung
Danke für Ihr Feedback!
Awesome!
Completion rate improved to 4.17single