欢迎大家来到我的博客http://unity.gopedu.com/home.php?mod=space&uid=3352&do=blog&view=me&from=space
SQL高级查询
--内连接查询(跟表的位置无关)
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
--like模糊查询
select id,name from users where name like '%a%'
--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 avg
select sum(id) as 总和 from users
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
--分组
select id,avg(id) as 平均 from users group by id
select id,avg(id) as 平均 from users group by id,name
请继续关注我的博客
http://unity.gopedu.com/home.php?mod=space&uid=3352&do=blog&view=me&from=space
更多精彩尽在http://www.gopedu.com/