Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the considerations for using SQL aggregate functions and sorting

Shulou Source: shulou.com Published: 2022-05-31 23:45:03 10月01日 Update

This article mainly introduces the use of SQL aggregation functions and sorting considerations, which have certain reference value, interested friends can refer to, I hope you have a lot of gains after reading this article, the following let Xiaobian take you to understand.

What are the considerations for using SQL aggregate functions and sorting?

count function

Grammar:

Select count(*)| count(column name) from table_name [where_definition];Select count(id) from stu;Select count(name) from stu where math > 90;select count (name) from stu where chines+math+English> 250;

sum function

Select sum (column name) from stu [where_definition];Select sum (column name),sum(column name), sum(column name) from stu [where_definition];Select sum (column name)+ sum (column name)+ sum(column name) from stu [where_definition];Select sum (column name)+sum(column name)+sum(column name) as Total score from stu [where_definition];Select sum (column name)/count(name) from stu [where_definition]; Select avg(math) from stu; Select avg(math + chines + english) from stu;Select max| min(column name) from stu;Select max(math + chines + english) from stu;Select min(math + chines + english) from stu;

Sort query results

Sort query results using the order by clause

Select column1, column2, column3 from table order by column asc|desc

Order by refers to the sorted column, or it can be the column name specified after select.

The order by clause should be at the end of the select statement

Select name, math from stu order by math;select name, math+english+chines from stu order by math+english+chines desc;select name, math+english+chines from stu where name like 'zhang%' order by math+english+chines desc;

Thank you for reading this article carefully. I hope that Xiaobian's "What are the precautions for using SQL aggregation functions and sorting" will be helpful to everyone. At the same time, I hope that everyone will support you a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Tags: Sort function article item notice clause result query value interest at the same time total score more friends knowledge editing industry sentence grammar information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Redmi Docker Shulou Information NVidia