看板 Database 關於我們 聯絡資訊
假設 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://www.ptt.cc/bbs/Database/M.1399973316.A.7E7.html
bulmungtw:謝謝幫忙解答 因為剛好在忙所以沒有辦法好好回訊息"" 05/13 22:34
bulmungtw:不過這樣所有的B好像都會變成A的樣子 05/13 22:35