作者nika (千少一)
看板Database
标题Re: [SQL ] 如何选出count(*)=1 的资料?
时间Thu Aug 16 12:39:46 2007
※ 引述《misssun (我要炸掉了)》之铭言:
: 先说明一下我的资料:
: TABLE:AA
: customerid againid
: 110 1
: 120 2
: 135 1
: 135 2
: 144 1
: 144 1
: 144 2
: 144 2
: 156 1
: 156 2
: 156 2
: 红色字体是我最後想要筛选出来的资料,
: 我的SQL如下:
: select customerid,againid,count(customerid)
: from AA
: where (时间区间)
: group by customerid,againid
: having count(customerid) = 1
: 但是最後总会连紫色字体的资料也被筛选出来
: 请问各位,我该如何更改语法,才能选取到我所需要的资料呢?!
: 先谢谢愿意回答我的人罗~~~~
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)
)
3.应该还有更好的,反正能解决问题都是好方法。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.59.39.178