MySQL的簡單查詢語句
阿新 • • 發佈:2019-01-15
排列 ike 查詢 having 模糊 價格 系列 語句 and
select * from Car where Name like ‘%型‘ %通配符代表任意多個字符
select * from Car where Name like ‘%奧迪%‘ _通配符代表任意一個字符
select * from Car where Name like ‘_馬%‘
四:排序
select * from Car order by Price asc 按照價格升序排列
select * from Car order by Price desc 按照價格降序排列
select * from Car order by Price,Oil 按照兩列進行排序,前面的為主要的
select count(Code) from Car 查詢表中有多少條數據
select max(Price) from Car 取價格的最大值
select min(Price) from Car 取價格的最小值
select sum(Price) from Car 取價格的總和
select avg(Price) from Car 取價格的平均值
六:分組查詢
select Brand from Car group by Brand having count(*)>2 查詢所有系列中數量大於2的
七:分頁查詢
select * from Car limit 0,5 跳過幾條數據取幾條數據
八:去重查詢
select distinct Brand from Car
查詢:
一:查詢所有數據
select * from Info 查所有數據
select Code,Name from Info 查特定列
二:根據條件查
select * from Info where Code=‘p001‘ 一個條件查詢
select * from Info where Code=‘p001‘ and Nation=‘n001‘ 多條件 並關系 查詢
select * from Info where Name=‘胡軍‘ or Nation=‘n001‘ 多條件 或關系 查詢
select * from Car where Price>=50 and Price<=60 範圍查詢
select * from Car where Price between 50 and 60 範圍查詢
三:模糊查詢
select * from Car where Name like ‘%型‘ %通配符代表任意多個字符
select * from Car where Name like ‘%奧迪%‘ _通配符代表任意一個字符
select * from Car where Name like ‘_馬%‘
四:排序
select * from Car order by Price asc 按照價格升序排列
select * from Car order by Price desc 按照價格降序排列
select * from Car order by Price,Oil 按照兩列進行排序,前面的為主要的
五:統計函數(聚合函數)
select count(Code) from Car 查詢表中有多少條數據
select max(Price) from Car 取價格的最大值
select min(Price) from Car 取價格的最小值
select sum(Price) from Car 取價格的總和
select avg(Price) from Car 取價格的平均值
六:分組查詢
select Brand from Car group by Brand having count(*)>2 查詢所有系列中數量大於2的
七:分頁查詢
select * from Car limit 0,5 跳過幾條數據取幾條數據
八:去重查詢
select distinct Brand from Car
MySQL的簡單查詢語句