如何减去此查询的结果:
SELECT COUNT(Laptops) FROM (SELECT aaaUser.FIRST_NAME AS User,COUNT(workstation.WORKSTATIONNAME) AS Laptops FROM SystemInfo workstation
LEFT JOIN Resources resource ON workstation.WORKSTATIONID=resource.RESOURCEID
LEFT JOIN ResourceOwner rOwner ON resource.RESOURCEID=rOwner.RESOURCEID
LEFT JOIN ResourceAssociation rToAsset ON rOwner.RESOURCEOWNERID=rToAsset.RESOURCEOWNERID
LEFT JOIN SDUser sdUser ON rOwner.USERID=sdUser.USERID
LEFT JOIN AaaUser aaaUser ON sdUser.USERID=aaaUser.USER_ID WHERE ( aaaUser.FIRST_NAME IS NOT NULL) AND ISSERVER=0
GROUP BY "User"
HAVING Laptops > 1
ORDER BY Laptops DESC) AS e
来自这个:
SELECT SUM(Laptops) FROM (SELECT aaaUser.FIRST_NAME AS User,COUNT(workstation.WORKSTATIONNAME) AS Laptops FROM SystemInfo workstation
LEFT JOIN Resources resource ON workstation.WORKSTATIONID=resource.RESOURCEID
LEFT JOIN ResourceOwner rOwner ON resource.RESOURCEID=rOwner.RESOURCEID
LEFT JOIN ResourceAssociation rToAsset ON rOwner.RESOURCEOWNERID=rToAsset.RESOURCEOWNERID
LEFT JOIN SDUser sdUser ON rOwner.USERID=sdUser.USERID
LEFT JOIN AaaUser aaaUser ON sdUser.USERID=aaaUser.USER_ID WHERE ( aaaUser.FIRST_NAME IS NOT NULL) AND ISSERVER=0
GROUP BY "User"
HAVING Laptops > 1
ORDER BY Laptops DESC) AS e
虽然只使用一个查询?
我正在尝试在不支持运行多个查询的产品中创建报表 - 因此临时表不是一个选项。
提前致谢,
本
答案 0 :(得分:4)
除非我遗漏了什么,否则你不能这样做吗?
SELECT SUM(Laptops) - COUNT(Laptops)
FROM (SELECT aaaUser.FIRST_NAME AS User,COUNT(workstation.WORKSTATIONNAME) AS Laptops FROM SystemInfo workstation
LEFT JOIN Resources resource ON workstation.WORKSTATIONID=resource.RESOURCEID
LEFT JOIN ResourceOwner rOwner ON resource.RESOURCEID=rOwner.RESOURCEID
LEFT JOIN ResourceAssociation rToAsset ON rOwner.RESOURCEOWNERID=rToAsset.RESOURCEOWNERID
LEFT JOIN SDUser sdUser ON rOwner.USERID=sdUser.USERID
LEFT JOIN AaaUser aaaUser ON sdUser.USERID=aaaUser.USER_ID WHERE ( aaaUser.FIRST_NAME IS NOT NULL) AND ISSERVER=0
GROUP BY "User"
HAVING Laptops > 1
ORDER BY Laptops DESC) AS e
答案 1 :(得分:2)
SELECT SUM(Laptops) - COUNT(Laptops)
from ...
因为您的汇总函数将是应用于GROUP
的结果的最后一项。
答案 2 :(得分:0)
SELECT (SELECT query 1 ... ...) - (SELECT query 2 ... ...) AS 'value';