简单的增删改查

2023-11-29  本文已影响0人  xueyueshuai

insert into user(username,password) values('1','11');
insert into user(username,password) values('2','22'),('3','33');

delete from user where id = 1;

update user set username='222',password='123456' where id = 1;

select [all|distinct] * from user
 [where id=1]
 [group by sex having 聚合后的字段>3]
 [order by id  asc|desc]
 [limit n,m];
in(1,2,3)
between(100,200)
模糊查询  字段名 like '%a%';
select id,name,age,sex,concat(id,'号叫',name,',年龄',age,'岁') as user_info_str from user; //查询添加新字段
select id,name,age,if(sex=0,'man','woman') as sex from user; //查询结果sql里if判断
select 
  * 
from 
(select id,name,age,if(sex=0,'man','woman') as sex from user) aa 
where aa.id=1; //查询再查询
select 
  id,
  name,
  age,
  (case when sex=0 then 'man' when sex=1 then 'woman' else 'other' end ) as sex 
from user;     //case在sql里的语法
select group_concat(id) from user;    // 字符串 “1,2,3,4,5,6”
上一篇下一篇

猜你喜欢

热点阅读