日期:2014-05-17  浏览次数:20422 次

请教此查询语句。大家给看看。
运行此语句
SELECT * FROM _Inventory where ItemID in (select ID64 from _Items WHERE (MagParamNum =6 ) AND (MagParam1 > 0) )
ORDER BY CharID
结果如下:

ID SOLT ITEMID

31069 19 1267742
31069 14 1398592
31069 67 1433251
31087 6 1278191
31096 6 1389209
31096 58 1311753
31103 24 1287728
31107 1 1458125
31120 6 1435518
31125 6 1365861
31135 4 1387962
31135 1 1293904
31135 0 1350325
31163 6 1372314
31210 4 1369660
31210 0 1378087

我现在想把查询出来ID能自动显示数量。就是多少个ID 符合查询语句规则。不需要显示出来具体的ITEMID数字。以上面为例,能直接显示出 ID=31069 共3个,ID=31087 共一个 ID=31096共2个等等。。 直接查询出ID后面显示出数量。

该怎么写查询语句?

------解决方案--------------------
with tb as
(
SELECT * FROM _Inventory where ItemID in (select ID64 from _Items WHERE (MagParamNum =6 ) AND (MagParam1 > 0) )
ORDER BY CharID
)
select ID, count(1)
from tb
group by ID
------解决方案--------------------
SQL code
select id,count(1)  
from (
SELECT * FROM _Inventory where ItemID in (select ID64 from _Items WHERE (MagParamNum =6 ) AND (MagParam1 > 0) ) ) group by id