作者iping (梅子绿茶)
看板Database
标题Re: [SQL ] 如何选出count(*)=1 的资料?
时间Fri Aug 17 01:12:35 2007
※ 引述《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