unity学习,希望我的博客能给朋友们带来帮助
模糊查询:
Like
查询时,字段中的内容并不一定与查询内容完全匹配,只要字段中含有这些内容
select id,name from users where name like 'a%'
select id,name from users where name like '%a%'--这种形式指只要有a就可以了,不在意a所在的位置
Is null
把某一字段中内容为空的记录查询出来
Between。。。And
把某一字段中内容在特定范围内的记录查询出来
select id,name from users where id between 1 and 2
select id,name from users where id >=1 and id<=2 ---两种方法都可以
In
把某一字段中内容与所列出的查询内容列表匹配的记录查询出来
select id,name from users where id in(1,2,3)
聚合函数
sum
select sum(id) as 总和 from users
avg
select avg(id) as 平均 from users
Max min
select max(id) as 最大,min(id) as 最小 from users
count
select count(*) as 总人数 from users
select count(password) as 总人数 from users
分组查询
group by
select id,avg(id) as 平均 from users group by id --单行
select id,avg(id) as 平均 from users group by id,name --多行
Having
Select StudentID as 学员编号,CourseID as 内部测试, AVG(Score) as 内部测试平均成绩
from Score group by StudentID,CourseID having count(Score)>1
分组查询对比
1、where子句从数据源中去掉不符合其搜索条件的数据
2、group by子句搜集数据行到各个组中,统计函数为各个组计算统计值
3、having子句去掉不符合其组搜索条件的各组数据行
多表联合查询
内连接查询(跟表的位置无关)
select u.name,s.grade from score as s inner join users as u on s.uid=u.id
select u.name,s.grade from users as u inner join score as s on s.uid=u.id
左外连接查询(跟表的位置有关)
select u.name,s.grade from score as s left join users as u on s.uid=u.id
select u.name,s.grade from users as u left join score as s on s.uid=u.id
右外连接查询(跟表的位置有关)
select u.name,s.grade from score as s right join users as u on s.uid=u.id
select u.name,s.grade from users as u right join score as s on s.uid=u.id
更多精彩请点击 http://www.gopedu.com/article