データベース選択クエリ

データベースのクエリについては、構築したテーブルに対してクエリを実行し、コマンドごとに条件に合うデータをテーブルに表示します。

ここで、students というテーブルを作成し、すべてのデータがこのテーブルからクエリされるとします。

テーブル内のすべてのデータをクエリ: select * from table name

 select * from student;

姓が張である同級生の名前を見つける

  • 好き
  • % は、任意の数の任意の文字を意味します
  • _ は任意の文字を意味します

select * from students where cname like '张';
select * from students where cname like '张%';
select * from students where cname like '张_';

重複データを明確に排除

When querying data, the query results may have a lot of duplicate data. 繰り返したくない場合は、distinct を使用して重複排除を実現できます: テーブル名から個別のフィールド名を選択します 

 select distinct cno from student;

 null 値と null 以外の値を判断する

空の値は null です。null 以外の値は null ではありません

select * from students where cage is null;

並べ替え順

order by句asc(デフォルト)昇順/降順を使用してソート

select * from table name order by column 1 asc|desc [, column 2 asc|desc,...]

おすすめ

転載: blog.csdn.net/qq_64573579/article/details/127956409