weixin_慕村5439658
as后面的部门加上单引号试试
慕UI2314908
as 是别名 。select username,decode() as '部门' from users; 其中decode就是一个新的展示字段
180416
select case column_name1
when value1 then result1
[when value2 then result2.... ][else result]
end [as column_new_name]
[,case
when expr1 then result1
[when expr2 then result2...]
[else result]
end [as column_new_name]
[,case...]
]
from tb_name;
成君
你这是问题还是笔记
GoogleLens
你在username后面加个salary字段就可以了啊
qq_删不掉沉醉_0
customer这个单词后面是不是少加了S,一般语法规则是复数形式
衣锦返乡
不类似,1.Decode是Oracle特有的;2.case...when 是Oracle, SQL Server,MySQL 都可用;3.Decode 只能用做相等判断,但是可以配合sign函数进行大于,小于,等于的判断;case可用于=,>=,<,<=,<>,is null,is not null 等的判断;4.Decode使用起来比较简洁,Case虽然复杂但更为灵活
qq_无言_51
select entrylane
, case
when entrylane<=10 then '普通车'
when entrylane>10 then '专用车道'
end as '车道分类'
from exit2015070020203;
啊梨真神奇
部门是字段名,不用加引号
qq_黄了青梅_0
举个例子:
测试数据:
usernam age
1 lili 19
2 toto 17
select username,(case age
when 19 then '成年人'
when 17 then '未成年人'
else 'xx') as age_str
from users;
查询结果:
username age_str
1 lili 成年人
2 toto 未成年人
夏日阳光haha
你拍一我拍三
工资水平是字段名,不用加单引号,平字没了,应该是字段允许显示的字符数问题