简单的Sql 问题(50分)

  • 主题发起人 主题发起人 小穷仔
  • 开始时间 开始时间

小穷仔

Unregistered / Unconfirmed
GUEST, unregistred user!
用Sql server 7.0 数据库如下:
库A : 库B
ID char(10) primary key type char(10)
type char(10) detail Text
...

每一个人可以在若干个type中选一个
现在要显示库A中某种type的个数小于15的type,我写来写去,要么说少having,要么说少group by 请帮忙!

 
SELECT ID, Count(type) AS countA
FROM A
GROUP BY ID,type
HAVING (Count(type)<15);
 
SELECT ID, Count(type) AS countA
FROM A
GROUP BY ID,count(type)
HAVING (Count(type)<15)

我没试过,
如果gxg8816的办法不行,试试这个
 
如果不返回ID:

SELECT type, Count(type) AS countA
FROM A
GROUP BY type
HAVING (Count(type)<15);

 
>>GROUP BY ID,count(type)
好像GROUP BY 子句不能带集合函数.
 
gxg8816 说的应该是对的
 
意外,上面竟然打错了
SELECT ID, Count(type) AS countA
FROM A
GROUP BY ID,CountA
HAVING (Count(type)<15)
 
用SQL Builer(TQuery控件下的)列出查询条件,再把查询语句另存为文件不就一目了
然了?
 
多人接受答案了。
 
后退
顶部