1.查询语句:
select “栏目名” from “表名”
select * from A
去重distinct语句:
select distinct name from A
条件查询:Where and or
select * from A Where score >60 and score<80
函数条件查询:having
select name,sum(score) from A group by name having sum(score)>668
查询相同字段不同值:in(不连续)
select * from A Where name in(“Leo”,“Xua”)
between(连续)
select * from A Where score between “70” and “90”
模糊查询:Like
select * from A Where name like “王%”
“A_Z”(ABZ),“A%”,“%A”,“%A%”;
排序:order by (des,asc)默认asc;
select * from A order by age desc
函数:avg,count,max,min,sum
select 函数(栏目) from A
select count(score) from A where score>=80
分组:group by
select name,sum(score) from A group by name;
别名:as
select 表别名.栏目名 栏目别名 from 表名 as 表别名
select a.name as “姓名” from table as a
多表查询:join
select a.name,b.class,sum(a.score)
from aaa as a,bbb as b
where a.name=b.name
group by a.name;
外连接:outer join
left outer join 左外
right outer join 右外
full outer join 全外
select a.name,b.class,sum(a.score)
from aaa as A right join bbb as b
on a.name=b.name
group by a.name
子查询:
select name,sum(score)
from a
where name in
(select name from b where class=“一班”)
group by name
网友评论