I have just added a few more columns (clients.site2_ipaddress clients.site3_ipaddress and so on until clients.site10_ipaddress)
My current query that I have tried to change to add an extra join query:
join clients on clients.site1_ipaddress
and clients.site2_ipaddress = ipaccounting.src_address
and
join clients on clients.site1_ipaddress
and clients.site2_ipaddress = ipaccounting.dst_address
The output changes everything to site2_ipaddress and only gives one row of data, I need it to add the upload_bytes, download_bytes and total_bytes combined for each of the IP addresses in each columns (site1_ipaddress, site2_ipaddress and so on)
For the life of me I cannot figure out what I am doing wrong...
I also need the output of the rows to add each IP Address with a comma and space, for example: lets say one of my clients have two sites, site1_ipaddress=192.168.1.2 and site2_ipaddress=192.168.1.3
My output needs to be:
ip_address | upload_bytes | download_bytes | total_bytes | .....
192.168.1.2, 192.168.1.3 | upload_bytes? | download_bytes? | total_bytes? | .....
Is that possible?
My complete query with the extra join is:
SELECT
ip_address,
SUM(upload_bytes) AS upload_bytes,
SUM(download_bytes) AS download_bytes,
SUM(upload_bytes + download_bytes) AS totalbytes,
package_id,
username,
userid,
networkaccess,
packagename,
speedlimit,
threshold,
throttlelimit,
extendeddata,
datalimitamount,
accountingdays
FROM
(
(
SELECT
ipaccounting.src_address AS ip_address,
SUM(ipaccounting.bytes) AS upload_bytes,
0 AS download_bytes,
clients.username,
clients.userid,
clients.networkaccess,
clients.extendeddata,
datapackages.package_id,
datapackages.packagename,
datapackages.speedlimit,
datapackages.threshold,
datapackages.throttlelimit,
datapackages.datalimitamount,
datapackages.accountingdays
FROM
ipaccounting
JOIN clients ON clients.ipaddress AND clients.`site2_ipaddress` = ipaccounting.src_address
JOIN datapackages ON datapackages.package_id = clients.datapackage
WHERE
dst_address NOT BETWEEN INET_NTOA('192.168.0.1') AND INET_NTOA('192.168.255.254') AND timeanddate BETWEEN SUBDATE(
CURRENT_TIMESTAMP(), INTERVAL datapackages.accountingdays DAY) AND CURRENT_TIMESTAMP()
GROUP BY
src_address)
UNION ALL
(
SELECT
ipaccounting.dst_address AS ip_address,
0 AS upload_bytes,
SUM(ipaccounting.bytes) AS download_bytes,
clients.username,
clients.userid,
clients.networkaccess,
clients.extendeddata,
datapackages.package_id,
datapackages.packagename,
datapackages.speedlimit,
datapackages.threshold,
datapackages.throttlelimit,
datapackages.datalimitamount,
datapackages.accountingdays
FROM
ipaccounting
JOIN clients ON clients.ipaddress AND clients.`site2_ipaddress` = ipaccounting.dst_address
JOIN datapackages ON datapackages.package_id = clients.datapackage
WHERE
src_address NOT BETWEEN INET_NTOA('192.168.0.1') AND INET_NTOA('192.168.255.254') AND timeanddate BETWEEN SUBDATE(
CURRENT_TIMESTAMP(), INTERVAL datapackages.accountingdays DAY) AND CURRENT_TIMESTAMP()
GROUP BY
dst_address)
) a
GROUP BY
ip_address
ORDER BY
INET_ATON(ip_address)
Clients Table:
IP Accounting Table:


{}button in the toolbar.