当我在create view构造中使用此代码时,它返回空结果集。 我尝试在案例后使用列名并删除行中的列名...没有变化......任何想法。我已经确定问题是在案例陈述中通过评论并运行它并且它工作正常....
DROP TABLE IF EXISTS `duplicaterecords`;
CREATE TABLE `duplicaterecords` (
`RRID` int(11) DEFAULT NULL,
`duplicateInfo` varchar(200) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `duplicaterecords` (`RRID`, `duplicateInfo`)
VALUES
(3920011,'Repeated:12009:CLEAR'),
(3920011,'Repeated:12012:CLEAR'),
(4233901,'Repeated:18129:HIT'),
(4820129,'Repeated:22901:PENDING'),
(4820129,'Repeated:22983:PENDING'),
(4233901,'Duplicate:5555555:CLEAR');
select grouped.*
, base.duplicateInfo
from
(
select grouped.RRID, max(grouped.duplicateInfoId) duplicateInfoId
from (
select RRID
, cast(substring_index(substring_index(duplicateInfo,':',2 ),':',-1) as unsigned) duplicateInfoId
, duplicateInfo
from duplicateRecords
) grouped
group by grouped.RRID
) grouped
inner join (
select RRID
, cast(substring_index(substring_index(duplicateInfo,':',2 ),':',-1) as unsigned) duplicateInfoId
, duplicateInfo
from duplicateRecords
) base
on grouped.duplicateInfoId = base.duplicateInfoId ;
-- example results
RRID duplicateInfoId duplicateInfo
3920011 12012 Repeated:12012:CLEAR
4233901 5555555 Duplicate:5555555:CLEAR
4820129 22983 Repeated:22983:PENDING
答案 0 :(得分:0)
就像这个例子一样:
尝试运行此
set @fulfillStatus = 1;
select
CASE
when @fulfillStatus = 0 then 'open'
when @fulfillStatus = 1 then 'processing'
when @fulfillStatus = 2 then 'complete'
when @fulfillStatus = 5 then 'Shipped'
when @fulfillStatus = 9 then 'void'
else "None"
END as "Order Status"