SQL条件查询

本文记录MySQL学习过程中遇到的SQL条件查询~

where语句表示条件过滤。满足条件操作,不满足不操作,多用于数据的查询与修改。

格式:

select 字段  from 表名  where 条件;  

while条件的种类如下:

例如:

查询所有吃饭支出记录
SELECT * FROM zhangwu WHERE name = '吃饭支出';

查询出金额大于1000的信息
SELECT * FROM zhangwu WHERE money >1000;

查询出金额在2000-5000之间的账务信息
SELECT * FROM zhangwu WHERE money >=2000 AND money <=5000;
或
SELECT * FROM zhangwu WHERE money BETWEEN 2000 AND 5000;

查询出金额是1000或5000或3500的商品信息
SELECT * FROM zhangwu WHERE money =1000 OR money =5000 OR money =3500;
或
SELECT * FROM zhangwu WHERE money IN(1000,5000,3500);

查询出账务名称包含”支出”的账务信息。
SELECT * FROM zhangwu WHERE name LIKE "%支出%";

查询出账务名称中是无五个字的账务信息
SELECT * FROM gjp_ledger WHERE ldesc LIKE "_____"; -- 五个下划线_

查询出账务名称不为null账务信息
SELECT * FROM zhangwu WHERE name IS NOT NULL;
SELECT * FROM zhangwu WHERE NOT (name IS NULL);

标签: none