ホームページ  >  記事  >  データベース  >  SQL集計関数とソート

SQL集計関数とソート

php中世界最好的语言
php中世界最好的语言オリジナル
2018-03-26 09:40:042164ブラウズ

今回は SQL の集計関数と並べ替えについて説明します。SQL 集計関数と並べ替えを使用するときの注意事項 について、実際の事例を見てみましょう。

count関数

構文:

Select count(*)|count(列名) from table_name [where where_defination];Select count(id) from stu;Select count(name) from stu where math > 90;select count (name) from stu where chines+math+English> 250;
sum関数

Select sum (列名) from stu [where where_defination];
Select sum (列名),sum(列名), sum(列名) from stu [where where_definition];
Select sum (列名)+sum(列名)+ sum(列名) from stu [where where_definition];
Select sum (列名)+sum(列名)+sum(列名) as 总分 from stu [where where_definition];
Select sum (列名)/count(name) from stu [where where_defination];
Select avg(math) from stu;
Select avg(math + chines + english) from stu;
Select max|min(列名) from stu;
Select max(math + chines + english) from stu;
Select min(math + chines + english) from stu;
Sort

queryresults

クエリ結果を並べ替えるには

order by句を使用します

Select column1, column2, column3 from table order by column asc|desc
order byは並べ替える列を参照します。 select

order by 句の後に指定された列名は、select ステートメントの最後に配置する必要があります

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;

SQL集計関数とソート

SQL集計関数とソート

この記事の事例を読んだ後は、この方法を習得したと思います。興味深い情報が満載です。PHP 中国語 Web サイトの他の関連記事にもご注目ください。

推奨読書:

ページングクエリの使用方法の詳細な説明

JS での日付関連関数の使用の詳細な説明

以上がSQL集計関数とソートの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。