作者cutekid (可爱小孩子)
看板Database
标题Re: [SQL ] SQL指令的问题请教
时间Tue May 13 17:28:33 2014
假设 table 的 primary key = {id,type} 且
相同 ID 下 type 有 A 或 B 时不再有其它 type
可如下做(MSSQL 语法):
select id,type,sum(val) as val
from (
select
id,
type =
case type
when 'B' then 'A' -- 将 type 'B' 取代成 type 'A'
else type
end,
val
from table
where date = '2014/05/13'
) as t
group by id,type
※ 引述《bulmungtw (Lance)》之铭言:
: 想求助一下
: http://i.imgur.com/cCHbwbf.png
: 假如我现在已经
: select ID, TYPE, VAL
: from table
: where date ='2014/05/13'
: 出现出来左边这个结果
: 那想呈现出右边的结果应该怎麽做呢?
: 相同ID且TYPE有A有B,VAL相加,TYPE只显示A ;此外不管
: 越看越混乱 囧
: 谢谢!!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 210.61.233.210
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Database/M.1399973316.A.7E7.html
1F:推 bulmungtw:谢谢帮忙解答 因为刚好在忙所以没有办法好好回讯息"" 05/13 22:34
2F:→ bulmungtw:不过这样所有的B好像都会变成A的样子 05/13 22:35