Re: [SQL ] 同一表格同一欄位資料統計

看板Database作者 (優質的藍色射手)時間12年前 (2013/11/21 09:28), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串4/6 (看更多)
※ 引述《qwertmn (抽筋)》之銘言: : ※ 引述《joedenkidd (優質的藍色射手)》之銘言: : : Dear 版友 : : select sum(*) from table1 where finish =1; //找出完成的資料 : : select sum(*) from table1 where finsih =0; //找出未完成的資料 : : 想請問一下,要如何將上面兩個查尋合併成一個 : select : count(if(finish=1, true, null)) as f1, : count(if(finish=0, true, null)) as f0; : 這樣? cutekid大大的方法,可以用,但因為我敘述不清,所以不適用,歹勢 select finish,sum(*) from yield_process where finish=0 or finish=1 group by fi nish qwertmn大大的方法我試了,無法執行,不知是因為pgsql不支援或是其他原因 但是,我發現我發問的問題有瑕疵,不好意思 finish 的型態是 character,記錄的是完成時間 class是品名,盤子、杯子..... 所以我都用最笨的方式分兩次尋找 select sum(*) from table where finish !='' group by class //當完成的時候,這 一欄不會是空的 select sun(*) from table where finish='' group by class //當完成的時候,這一欄 會是空的 所以我想說要將這兩個整合成一個,顯示結果如下 品名 完成 未完成 盤子 6 3 杯子 8 4 不知道有沒有辦法用一個語法就完成這樣的一件事? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.44.30.244

11/21 10:00, , 1F
postgres 看這個試試..http://ppt.cc/vGaM
11/21 10:00, 1F
文章代碼(AID): #1IZM6Ydc (Database)
討論串 (同標題文章)
文章代碼(AID): #1IZM6Ydc (Database)