Re: [SQL ] 如何選出count(*)=1 的資料?
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 9 篇):