select * from xsb;
注:* 代表所有的字段,也可以改为某个字段,就是查询部分字段,如下
select xm,nl from xsb;
select * from xsb where xm=‘张三‘;
select * from xsb where xm=‘张三‘ or xm=‘李四‘;
select * from xsb where xm!=‘张三‘ ;
select * from xsb where xm=‘李四‘and nl=18;
select * from xsb where xm like ‘李%‘ or xm like ‘张%‘;
select * from xsb where jg in(‘北京‘,‘上海‘,‘山东‘);
select distinct jg from xsb;
select * from xsb order by nl asc;
select * from xsb order by nl desc;
select * from xsb where xb=‘男‘ order by nl desc;
select xh from cjb where cj is not null;
select * from xsb limit 1,4;
select * from xsb limit 5;
select * from xsb where nl between 18 and 21;
select count(*) as ‘总人数‘ from xsb where nl>20;
select count(*) as ‘总记录数‘ from cjb;
select sum(cj) as ‘总分‘ from cjb;
select count(*) as ‘总人数‘,kch as‘课程号‘,sum(cj) as ‘总成绩‘ from cjb group by kch;
select xh from cjb where cj<60 GROUp by xh having count(*)>=2 ;
select sum(cj) as ‘总成绩‘ from cjb where kch in (select kch from kcb where kcm=‘java语言‘);
select cj as ‘成绩‘ from cjb where xh in(select xh from xsb where xm=‘张三‘and bj=‘1班‘) and kch in(select kch from kcb where kcm=‘java语言‘);
select xm,kcb.kch,cj from xsb,cjb,kcb where xsb.xh=cjb.xh AND kcb.kch=cjb.kch AND xm=‘张三‘;
select xm,cj from xsb left join cjb on xsb.xh=cjb.xh ;
Create table areas(
aid int primary key,
atitle varchar(20),
pid int
);
insert into areas values (‘130000‘, ‘河北省‘, NULL),
(‘130100‘, ‘石家庄市‘, ‘130000‘),
(‘130400‘, ‘邯郸市‘, ‘130000‘),
(‘130600‘, ‘保定市‘, ‘130000‘),
(‘130700‘, ‘张家口市‘, ‘130000‘),
(‘130800‘, ‘承德市‘, ‘130000‘),
(‘410000‘, ‘河南省‘, NULL),
(‘410100‘, ‘郑州市‘, ‘410000‘),
(‘410300‘, ‘洛阳市‘, ‘410000‘),
(‘410500‘, ‘安阳市‘, ‘410000‘),
(‘410700‘, ‘新乡市‘, ‘410000‘),
(‘410800‘, ‘焦作市‘, ‘410000‘);
select * from areas where pid in (select aid from areas where atitle=‘河北省‘);
select * from areas as p inner join areas as c on p.aid=c.pid;
原文:https://www.cnblogs.com/zjp119/p/12389931.html
如果您也喜欢它,动动您的小指点个赞吧