Du måste gruppera kolumnen infection och (ip &ipc ) på ett annat sätt och sedan gå med dem med hjälp av en underfråga så här:
SELECT t1.ip, t1.isp, t2.infection, t1.ipc, t1. ispc, t2.incount
FROM
(SELECT ip, isp, infection, COUNT(ip) as ipc, COUNT(isp) as ispc
FROM (
SELECT ip, isp, infection
FROM tbl1
UNION ALL
SELECT ip, isp, infection
FROM tbl2
UNION ALL
SELECT ip, isp, infection
FROM tbl3
)x
GROUP BY ip, isp) t1
JOIN
(SELECT ip, isp, infection, COUNT(infection) as incount
FROM (
SELECT ip, isp, infection
FROM tbl1
UNION ALL
SELECT ip, isp, infection
FROM tbl2
UNION ALL
SELECT ip, isp, infection
FROM tbl3
)x
GROUP BY ip, isp, infection)t2
ON t1.ip = t2.ip
ORDER BY ip, isp, infection Desc
Se denna SQLFiddle
Obs! Jag tror att din önskade utdata är fel eftersom:
- I
Table3det finns ingeninfectionförip=6men det finns i din utdata infectionothersaknas i din utdata (istället finns detmalware)