oracle - SQL Query returns no rows -
i'm working on query list of computers have more 1 antivirus installed. unfortunately i'm unable query return anything. can see in screenshots below have setup data when query working result set contain data on devices 1, 2, , 3.


here i've got currently:
select d.ip_address "ip address", d.name "computer name", av.name "antivirus name", count(av.deviceid) "# of av installed" devices d join anti_virus_products av on d.deviceid = av.deviceid group d.ip_address, d.name, av.name having count(av.deviceid) > 1;
you need remove antivirus name av.name select , group by. including in results, group by create new row each computer , antivirus name -- because values create unique group.
select d.ip_address "ip address", d.name "computer name", count(av.deviceid) "# of av installed" devices d join anti_virus_products av on d.deviceid = av.deviceid group d.ip_address, d.name having count(av.deviceid) > 1; update based on comment expand query list names of av software installed on devices:
you partition count function. couldn't find link oracle documentation this, sql server syntax over clause seems work oracle. see example query on sql fiddle
select d.ip_address "ip address", d.name "computer name", d.deviceid, av.name "antivirus name", count(*) on (partition d.ip_address, d.name) "total # of av installed" devices d join anti_virus_products av on d.deviceid = av.deviceid group d.ip_address, d.name, d.deviceid, av.name; this example query return 1 row each device , antivirus pair , include total number of av installed on device.
i'm not sure if solve problem, provides additional data you're looking for.
Comments
Post a Comment