Query Sorting, Grouping and Aggregation of Database Principles (2) (Day 15)

1. Sorting of query results:

ASC: Specify the sorting method as ascending, the default value

DESC: Specifies that the sorting method is descending order

    1. Sort a single column SELECT * FROM [User] ORDER BY age DESC


    2. Sort on multiple columns SELECT * FROM [User] ORDER BY pwd,age


2. Grouping and summarizing query results

    1. Use aggregate functions for data statistics SELECT COUNT(*) FROM [User] 

Commonly used aggregation functions


      

    2. Use the GROUP BY clause for grouping summaries

        (1). Summarize a single column SELECT id FROM [User] GROUP BY id


    (2). Grouping and summarizing multiple columns SELECT id,age FROM [User] GROUP BY id,age


    3. Use the HAVING clause to set query conditions in the grouping SELECT id, age FROM [User] GROUP BY id, age HAVING age>=5


If HAVING and GROUP BY ALL are used together, the GROUP BY ALL effect will be canceled

    4. Use the COMPUTE keyword for detailed summary (I was mad, this (after the 2008 version) has been abandoned, I will say why it is always wrong)

3. Create a new table for query results

    

Guess you like

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