sql 語句 二
來源:程序員人生 發(fā)布時(shí)間:2015-08-03 08:44:47 閱讀次數(shù):3487次
選單列數(shù)據(jù)
select name from totoro;
選兩列數(shù)據(jù)
select id,name from totoro;
選單列中不重復(fù)的數(shù)據(jù)
select distinct name from totoro;
選出name列中名字是pangpang3的數(shù)據(jù)
select * from totoro where name='pangpang3';
選出age>3的數(shù)據(jù)
select * from totoro where age>3;
and
select * from totoro where id=1 and age=1;
or
select * from totoro where id=1 or age=3;
order by 排序
select age from totoro order by age;
選兩列,按age排序
select id,age from totoro order by age;
DESC,降序
select age,name from totoro order by name DESC;
ASC,升序
select name,id from totoro order by name ASC;
部份插
insert into totoro (id,name) values (10,'feifei');
部份更新
update totoro set id=13,name='mark' where age=9;
刪除
delete from totoro where id=1;
選前3行 limit
select * from totoro limit 3;
以i結(jié)尾的name
select * from totoro where name like '%i';
含om的name
select * from totoro where name like '%om%';
name第1個(gè)字符后是hu的
select * from totoro where name like '_hu';
name第2是a,第4是k
select * from totoro where name like '_a_k';
name是tom,ii
select * from totoro where name in ('tom','ii');
取anan和mary之間的name
select * from totoro where name between 'anan' and 'mary';
as指定別名
select name as n from totoro;
表名totoro as t
select t.id from totoro as t;
兩張表中id相等的name
select totoro.id,totoro.name,user.name from totoro,user where totoro.id=user.id;
join on
select totoro.id,totoro.name,user.name from totoro join user on totoro.id=user.id order by totoro.id;
取兩張表中id相同的數(shù)據(jù)
select totoro.id,totoro.name,user.name from totoro,user where totoro.id=user.id;
inner join
select totoro.id,totoro.name,user.id from totoro inner join user on totoro.id=user.id order by totoro.id;
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)