查询
来源:互联网 发布:windows 7 64 sp1补丁 编辑:程序博客网 时间:2024/04/28 19:23
欢迎来到我的博客,希望大家一起学习和讨论:
1、使用LIKE、BETWEEN、IN进行模糊查询
--like模糊查询
select id,name from users where name like '%b%'
--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)
2、在查询中使用聚合函数(avg,sum,max,max,count)
--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
3、使用GROUP BY进行分组查询
select id,avg(id) as 平均 from users group by id
select id,avg(id) as 平均 from users group by id,name
4、进行多表联结查询
<1>内联结(INNER JOIN)
<2>外联结
<3>左外联结 (LEFT JOIN)
<4>右外联结 (RIGHT JOIN)
<5>完整外联结(FULL JOIN)
<6>交叉联结(CROSS JOIN)
--内连接查询(跟表的位置无关)
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
0 0
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 查询
- 手把手教你搭建和配置Jenkins环境
- 电子商务系统的设计与实现(五):账务系统的功能接口设计
- eclipse控制台显示mysql数据库表的内容、数据库主键、Jdbc中带有变量的sql语句写法12-30-2014
- Flash Nexus5
- java抓包工具及配置
- 查询
- 9.5(2)十数之王
- Android Handler使用
- Lua数据结构 — lua_State(六)
- 数据库连接增,删,该、改,查
- 在ios android设备上使用 Protobuf (使用dll方式) .Net 2.0
- iOS ASI http 框架详解
- 在ios android设备上使用 Protobuf (使用源码方式) .Net 2.0 subset
- vi编辑器