Re: [SQL ] 如何選出count(*)=1 的資料?

看板Database作者 (梅子綠茶)時間18年前 (2007/08/17 01:12), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/9 (看更多)
※ 引述《nika (千少一)》之銘言: : 1.如果資料量就只有上面十一筆(資料筆數少)的話 : select customerid,againid : from AA : where (時間區間) : and customerid in ('110', '120') ps.' '不能用就換成" " : 這是一般SQL語法,任何資料庫都適用 : 2.以下方法我用db檔做不出來,但是MS SQL跟Oracle都可以 : select * from aa : where customerid in : ( : select customerid : from ( : select count(*) aa, customerid : from aa : where (時間區間) : group by customerid : having count(*) = 1) : ) select * from aa where customerid in (select customerid from aa where (時間區間) group by customerid having count(*)=1) MS-SQL的話, 用2層式查詢就夠了。 : 3.應該還有更好的,反正能解決問題都是好方法。 MS-SQL可以用QA/執行計畫檢查一下它執行的方法, 找出最佳效能的寫法。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.70.78.83
文章代碼(AID): #16n8M7LZ (Database)
討論串 (同標題文章)
文章代碼(AID): #16n8M7LZ (Database)