多欄位查詢
複製** **如下:
mysql> select id,name,birth from student;
所有字段查詢
複製** **如下:
mysql> select * from student;
where指定查詢
複製** **如下:
mysql> select * from student where id=901;
mysql> select * from student where id>=904;
mysql> select name from student where department='計算機系';
in指定集合查詢
複製** **如下:
mysql> select * from student where birth in(1988,1990);
mysql> select * from student where id in(903,906);
not in非範圍查詢
複製** **如下:
mysql> select * from student where birth not in(1990,1998);
between and指定範圍查詢
複製** **如下:
mysql> select * from student where birth between 1986 and 1988;
not between and不在指定範圍的查詢
複製** 代程式設計客棧碼如下:
mysql> select * from student where id not between 904 and 906;
like字串匹配查詢
複製** **如下:
mysql> select * from student where name like '_三';
mysql> select * from student where name like '張三';
mysql> select * from student where name like '張%';
not like不匹配查詢
複製** **如下:
mysql> select * from student where name not like '張%';
null查詢
複製** **如下:
mysqlwww.cppcns.com> select * from student where address is null;
and多條件查詢
複製** **如下:
mysql> select * from student where name like '張%' and birth>1985;
mysql> selegttrsysuict * from student where name like '張%' and birth>1985 and id like '%3';
or多條件查詢
複製** **如下:
mysql> se程式設計客棧lect * from student where id=905 or birth=1988;
mysql> select * from student where id=905 or birth=1988 or ***='女';
distinct查詢結果不重複
複製** **如下:
mysql> select distinct *** from student;
mysql> select distinct department from student;
order by查詢結果排序
複製** **如下:
mysql> select * from student order by birth;
mysql>trsysuigt; select * from student order by birth asc;
mysql> select * from student order by birth desc;
group by分組查詢
複製** **如下:
mysql> select ***,group_concat(name) from student group by ***;
mysql> select ***,count(name) from student group by ***;
正規表示式查詢
複製** **如下:
mysql> select * from student where birth regexp '1988|1990';
limit限制查詢結果數量
複製** **如下:
mysql> select * from student limit 2;
mysql> select * from student limit 1,3;
本文標題: mysql筆記之基本查詢的應用詳解
本文位址:
MySQL學習筆記之基本語句
一 連線mysql 格式 mysql h 主機位址 u 使用者名稱 p 使用者密碼 1 例1 連線到本機上的mysql。首先在開啟dos視窗,然後進入目錄 mysqlbin,再鍵入命令mysql uroot p,回車後提示你輸密碼,如果剛安裝好mysql,超級使用者root是沒有密碼的,故直接回車即...
MySQL查詢 1 基本查詢
建立資料庫 create database python test 1 charset utf8 使用資料庫 use python test 1 students表 create table students id int unsigned primary key auto increment no...
MySQL筆記之觸發器的應用
建立觸發器 建立只有乙個執行語句的觸發器 複製 如下 create trigger 觸發器名 before after 觸發事件 on 表名 for each row 執行語句 其中,觸發器名引數指要建立的觸發器的名字 before和after引數指定了觸發執行的時間,在事件之前或是之後 for e...