mysql查询语句
1.简单查询
select * from info; select Code as '代号',name as '姓名' from info;
2.条件查询
select * from car where code = 'c002'; select * from car where brand ='b001' and power = 130; #或用or
3.模糊查询
select * from car where name like '%奥迪%'; %代表任意多个字符包括0个 _代表一个字符
4.排序查询
asc:顺序排序(默认) desc:倒序排序
select * from car order by brand, powers desc; asc升序默认可以不写
5.离散查询
in() :查询符合括号里面的数据 not in() :除了括号里面的数据其他都查询
select * from car where code in('coo1','c003','c005','c007'); select * from car where code not in('coo1','c003','c005','c007');
6.统计查询(聚合函数)
select count(code) from car; 查询数据条数也可以count(*)这么写,性能低 select sum(price) from car; 求和 select max(code) from car; 最大 select min(brand) from car; 最小 select avg(price) from car; 平均
7.分组查询
select brand,count(*),Brand from Car group by Brand #把brand列的相同值组合起来,并这一条数据对该列或或其他列进行操作例如求平均值 select Brand from Car group by Brand having count(*)>3 #分组之后根据条件查询使用having 不使用where