mysql 查询条件
? 1簡單查詢?? select* from 表名
?????????????????????? select name as“姓名”fromstu???? (把name改為名字)
2條件查詢 where 后面跟條件? 條件要寫清楚
3模糊查詢? like? no like??? %代表任意多個字符?? _代表一個字符
4排序查詢? order by 字段 排序值 (desc降 asc升)
5范圍查詢???? between....and...
6離散查詢? in? notin
7聚合查詢?? sun 求和?? count數(shù)據(jù)條數(shù)?? max最大值? min最小值 avg平均值
8分頁查詢 limit 從第幾條開始,取多少數(shù)據(jù)
???????????????? 表名limit(pagesize-1)*5,5???? pagesize是頁數(shù) ? *5 是每頁條數(shù) ,5 取多少條
9去重查詢 distinct????? select distinct? 表段名 from 表名
10分組查詢 group by 字段? having 條件
select count(*),cno,group_concat(degree),sum(degree) from score group by cno ;
select cno,group_concat(degree),sum(degree) from score group by cno having count(*)>3
#分組之后根據(jù)條件查詢使用having 不使用where
高級查詢
?
?? Select * from student as stu,score as sc
where stu.sno = sc.sno and sc.sno = “103” ;
?
2.聯(lián)合查詢,對行的擴展
?
??? select Code,Name from Info
??? union
??? select Code,Name from Nation
?
3.子查詢
?
(1)無關(guān)子查詢
?
外層查詢 (里層查詢)
子查詢的結(jié)果當(dāng)做父查詢的條件
?
子查詢:select Code from Nation where Name='漢族'
父查詢:select * from Info where Nation = ''
?
??? select * from Info where Nation = (select Code from Nation where Name='漢族')
?
?
(2)相關(guān)子查詢
??? 查詢汽車表中油耗低于該系列平均油耗的所有汽車信息
?
??? 父查詢:select * from Car where Oil<(該系列平均油耗)
??? 子查詢:select avg(Oil) from Car where Brand = '某個系列'
?
??? select * from Car a where Oil<(select avg(Oil) from Car b where b.Brand = a.Brand )
轉(zhuǎn)載于:https://www.cnblogs.com/w-xibao/p/7759760.html
總結(jié)
以上是生活随笔為你收集整理的mysql 查询条件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。