普通查询

1.普通查询
select * from Info --查询所有内容--

select Code,Name from Info --查询某几列--

2.条件查询

select * from Info where Nation ='n001' --条件查询--

select *from Info where Nation ='n001' and Sex = true --满足两个条件的,用and,条件之间是并的关系--

select * from Info where Sex =false or Nation ='n002' --条件之间是或的关系,用or--

select * from Car where Price>50 and Price<60 --范围查询--

select * from Car where Price<30 or Price >60 --范围查询--

3.模糊查询

select * from ChinaStates where AreaName like '中%' --查询以‘中’开头的,关键字like,%代表任意多个字符

select *from ChinaStates where AreaName like '%城%' --查询包含‘城’这个字的信息--

select *from ChinaStates where AreaName like '_城%' --‘城’在第二个位置出现,下划线代表任意一个字符--

4.排序查询

select *from car order by Code desc --desc是降序的意思,asc是升序--

select *from car order by Brand,Powers --先按照Brand排序,再按照Powers排序--

5.统计查询(聚合函数)

select count(*) from Car --查询总条数--

select max(price) from Car --查询Price这一列的最大值,最小值换成min--

select avg(Price) from Car --查询平均值--

select sum(Price) from Car --查询总和--

6.分组查询

select Brand,count(*)from Car group by Brand --根据系列分组查看每组的数据条数,也可以求和,
求最大,最小,平均数--
以Brand来分组,看里面有多少条数据

select * from Car group by Brand having count(*)>2
以Brand分组,看里面数据大于2条的

7.分页查询

select * from Car limit 0,5 --跳过几条数据,取几条数据--
跳过0条数据,来取5条,取得是0-5条

select * from Car limit 5,5
跳过5条数据,来取5条,取得是6-10条


8.去重查询
select distinct Brand from Car

 

posted @ 2016-03-14 08:29  梦里梦到梦  阅读(197)  评论(0编辑  收藏  举报