我有一张表格如图所示
CREATE TABLE `document` (
`T1` varchar(50) DEFAULT NULL,
`T2` varchar(50) DEFAULT NULL,
`T3` varchar(50) DEFAULT NULL,
`T4` varchar(50) DEFAULT NULL,
`T5` varchar(50) DEFAULT NULL,
status int default 0
);
Insert into document (T1 , status ) values ('Pocorn',0);
Insert into document (T1 , T2 , status ) values ('Pocorn', 'Bucket' , 1);
Insert into document (T1 , T2 , T3 , status) values ('Pocorn', 'Chocka' , 'Small' , 2);
这是我的sqlfiddle http://sqlfiddle.com/#!2/d816e/2
我的问题是我有3个身份
0表示待定
1表示已批准
2表示拒绝
是否可以在提取时将值替换为待处理,已批准和已拒绝
答案 0 :(得分:2)
select t1, t2, t3, t4,
case
when status=0 then 'Pendig'
when status=1 then 'Approved'
when status=2 then 'Declined'
end
from document
答案 1 :(得分:1)
select case when status = 0
then 'pending'
when status = 1
then 'approved'
when status = 2
then 'declined'
end as status
from document