一.mysql單表查詢select:
1>簡單查詢
簡單查詢
select * from 表名;
select 字段1,字段2,...字段n from 表名;
2> 避免重複distinct(通常使用於某個字段)
select distinct 字段1 from 表名;
3> 通過四則運算查詢
select 字段1*12 from 表名;
select 字段1,字段2 as 新字段名 from 表名;(定義別名,逗號分隔要查詢的字段名)
select 字段1*15 sannual_fee from 表名;(定義別名)
4>定義顯示格式(將多個字段整合成一個字段顯示)
concat()函數用於連接字符串
select concat(字段1,‘新字段名‘,字段2)as 別名;
二.條件查詢
1.單條件查詢
select 字段1,字段2,字段3 from 表名 where 條件1;
2.多條件查詢(用and或者or連接)
select 字段1,字段2,字段3 from 表名 where 條件1 and 條件2;
3.關鍵字:between and(在某個區間內)
not between ...and....(不在某個區間內)
select 字段1,字段2 from 表 where 字段1 between 條件區間1 and 條件區間2;
4.關鍵字: is null(只能查找出來自己定義的null,手動添加的null不能查找出來)
is not null
5.關鍵字:in()
not in()
6.關鍵字:like 模糊查詢
%匹配任意多個字符
_ 明確匹配字符串的數量