Database---aggregate query

Aggregate query: vertical query, which calculates the value of a column and returns a single value; in addition, aggregate query ignores null values.
· count: count the number of rows in which the specified column is not NULL;
· sum: calculate the numerical sum of the specified column, if the specified column type is not a numerical type, the calculation result is 0;
· max: calculate the maximum value of the specified column , if the specified column is a string type, use the string sorting operation;
· min: calculate the minimum value of the specified column, if the specified column is a string type, use the string sorting operation;
· avg: calculate the specified column Average value, if the specified column type is not a numeric type, the result is 0;
SELECT COUNT(*) FROM PRODUCT; #Query all records in the table and return the number of records. SELECT COUNT(*) FROM PRODUCT WHERE PRICE>200; #Query the records with price greater than 200 in the table, and return the number of records greater than 200. SELECT COUNT(*) FROM PRODUCT WHERE CATEGORY_ID='C001'; #Query the records whose category_id is c001 in the query table, and return the number of records. SELECT SUM(PRICE) FROM PRODUCT WHERE CATEGORY_ID='C001'; #Query all prices whose category_id is c001, and return the sum of price SELECT AVG(PRICE) FROM PRODUCT WHERE CATEGORY_ID='C002';







#Query category_id is all prices of c002, and return the average price


SELECT MAX(PRICE),MIN(PRICE) FROM PRODUCT; #Query product table, return the maximum and minimum price

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325937620&siteId=291194637