-
case...when 语句的使用 case column_name when value1 then result1,... [else result] end 当column_name的值等于value的值时,使用result的值,都不等于的时候,使用else 里的值 ---------------------------------- 一、case...when语句的使用 语法1:CASE column_name WHEN value1 THEN result1 ... [ELSE resultn] END; 语法2:CASE WHEN column_name=value1 THEN result1 ...[ELSE resultn] END; 注:value1、result1需要加单引号,表示字符串,当多个when...then...使用时,中间用空格隔开即可,不能用逗号隔开。 case...when 语句的使用([when后面跟的是判断的条件,then是条件为真是显示出来的东西]): 1、select username,case usersname when 'aaa' then '计算机部门' when 'bbb' then '市场部门' else '其他部门' end as 部门 from users; 2、select username,case when username='aaa' then '计算机部门' when username='bbb' then '市场部门' else '其他部门' end as 部门 from users; *这个的用法就比较灵活*后面可以跟salary的条件。查看全部
-
insert into users values(4,'aaa',1000); select * from users order by username desc,salary asc;查看全部
-
select * from users order by id desc,salary asc;查看全部
-
select * from users order by id desc; //按降序排列查看全部
-
对查询结果排序查看全部
-
例:查询用户名是aaa或者bbb的用户信息 select * from users where username in('aaa','bbb');查看全部
-
select *from users where salary between 800 to 2000;查看全部
-
select *from users where username like 'a%';查看全部
-
模糊查询 通配符的使用(_,%) 一个_只能代表一个字符 %可以代表0到多个任意字符 使用LIKE查询查看全部
-
select * from users where not(username='aaa');查看全部
-
select * from users where username='aaa' or (salary>800 and salary<=2000);查看全部
-
select * from users where username='aaa' or salary>2000;查看全部
-
select username,salary from users where id=3;查看全部
-
select username from users where salary>800 and salary<>1800.5;查看全部
-
select username from users where salary>800;查看全部
举报
0/150
提交
取消