SQL语句-查询命令

以下如果是数字类型的键值,就不应该加单引号。
【=】等于
SELECT * FROM Persons WHERE City='Beijing'
SELECT * FROM 要查询的表名 WHERE 键名='键值'

【<>】不等于
SELECT * FROM Persons WHERE City<>'Beijing'
SELECT * FROM 要查询的表名 WHERE 键名<>'键值'

【>】大于
SELECT * FROM Persons WHERE CityCode>110000
SELECT * FROM 要查询的表名 WHERE 键名>键值

【BETWEEN...AND...】按范围查询
SELECT * FROM iPhone6 WHERE score BETWEEN 85 AND 90
SELECT * FROM 要查询的表名 WHERE 键名 BETWEEN 键值的最小取值范围 AND 键值的最大取值范围 

【LIKE...开头%】以开头查询
SELECT * FROM SysDetectItem WHERE reaction LIKE '采%'
SELECT * FROM 要查询的表名 WHERE 键名 LIKE '键值的开头%'

【LIKE...%结尾】以结尾查询
SELECT * FROM SysDetectItem WHERE reaction LIKE '%法'
SELECT * FROM 要查询的表名 WHERE 键名 LIKE '%键值的结尾'

【LIKE...%键值的关健词%】以关健词查询
SELECT * FROM SysDetectItem WHERE reaction LIKE '%法%'
SELECT * FROM 要查询的表名 WHERE 键名 LIKE '%键值的关健词%'

【ORDER BY ... ASC】升序排列
SELECT * FROM iPhone6  ORDER BY score ASC
SELECT * FROM 要查询的表名 ORDER BY 键名 ASC

【ORDER BY ... DESC】降序排列
SELECT * FROM iPhone6  ORDER BY score DESC
SELECT * FROM 要查询的表名 ORDER BY 键名 DESC

【IN】多键值查询
SELECT * FROM SysDetectItem WHERE unit IN ('mmol/L','μmol/L')
SELECT * FROM 要查询的表名 WHERE 键名 IN ('键值1','键值2')

 

你可能感兴趣的:(数据库)