SQL 语句查询
例如: 有一张 USER 表,USERS表中的字段 :user_name ,user_password, user_status(用户状态:0:取消,1:完成,2:接受) 现在我想查询表USERS 当user_status为0时显示取消、为1 完成 为2接受 如下:
user_name user_password user_status
李 123456 接受
[解决办法]
Oracel:
select user_name, user_password, decode(user_status, 0, '取消', 1, '完成', 2, '接受') user_status from USERS
SQL Server:
select user_name, user_password,
case user_status
when 0 then
'取消'
when 1 then
'完成'
when 2 then
'接受'
end user_status
from USERS
[解决办法]
select user_name, user_password, case user_status when 0 then '取消' when 1 then '完成' else '接受' end as user_status from [users]
SQL Server:
select user_name, user_password,
case user_status
when 0 then
'取消'
when 1 then
'完成'
when 2 then
'接受'
end user_status
from USERS