56,677
社区成员
发帖
与我相关
我的任务
分享
CREATE TABLE applyProcessPrice
(
pId BIGINT NOT NULL,
pBaseMsgId BIGINT ,
pPrice DOUBLE NOT NULL ,
pNo INT
)
;
insert into applyProcessPrice (pId,pBaseMsgId,pPrice,pNo) values(1,1,200,1);
insert into applyProcessPrice (pId,pBaseMsgId,pPrice,pNo) values(2,1,400,2);
insert into applyProcessPrice (pId,pBaseMsgId,pPrice,pNo) values(3,1,200,3);
insert into applyProcessPrice (pId,pBaseMsgId,pPrice,pNo) values(4,2,400,1);
insert into applyProcessPrice (pId,pBaseMsgId,pPrice,pNo) values(5,2,600,2);
insert into applyProcessPrice (pId,pBaseMsgId,pPrice,pNo) values(6,2,200,3);
insert into applyProcessPrice (pId,pBaseMsgId,pPrice,pNo) values(7,3,880,1);
insert into applyProcessPrice (pId,pBaseMsgId,pPrice,pNo) values(8,3,1100,2);
insert into applyProcessPrice (pId,pBaseMsgId,pPrice,pNo) values(9,3,300,3);
select pBaseMsgId,
MAX(CASE pno WHEN 1 THEN pprice ELSE 0 END ) as `价格1`,
MAX(CASE pno WHEN 2 THEN pprice ELSE 0 END ) as `价格2` ,
MAX(CASE pno WHEN 3 THEN pprice ELSE 0 END ) as `价格3`
from applyprocessprice
group by pBaseMsgId
select pBaseMsgId,
MAX(CASE pid WHEN 1 THEN pprice ELSE 0 END ) as `价格1`,
MAX(CASE pid WHEN 2 THEN pprice ELSE 0 END ) as `价格2` ,
MAX(CASE pid WHEN 3 THEN pprice ELSE 0 END ) as `价格3`
from applyprocessprice
group by pBaseMsgId
如仍有问题,贴出错误提示。