Reputation:
This is the query there I am using right now
Here they are:
SELECT Filetype AS 'Tipo do ficheiro',
((COUNT(Filetype) * 100) / (SELECT COUNT(*) FROM infofile)) AS 'Percentagem (%)',
NULL AS 'Total(KB)'
FROM infofile
GROUP BY Filetype
UNION ALL
SELECT NULL,
((COUNT(Filetype) * 100) / (SELECT COUNT(*) FROM infofile)),
SUM(Filesize)
FROM infofile
What I want to change here is the possibility to get the result of this query included on the main one
SELECT Filetype, SUM(Filesize) AS 'Total(KB)'
FROM infofile
GROUP BY Filetype
This is my output at the moment. What I want to add is the size of each extension. For example .exe - 225
Upvotes: 2
Views: 60
Reputation: 780
Can you try this one.
SELECT A.Filetype,
((COUNT(A.Filetype) * 100) / (SELECT COUNT(*) FROM infofile)) AS Percentagem,
B.filesize AS Totalkb
FROM infofile A,
(SELECT SUM(Filesize) filesize FROM infofile) B
GROUP BY Filetype,Totalkb
Upvotes: 0
Reputation: 15061
If it is a SUM
of everything then just put it in a sub query without any joins to the main query.
Also amended your brackets in the Percentagem
, be careful with BODMAS.
SELECT Filetype,
((COUNT(Filetype) * 100) / (SELECT COUNT(*) FROM infofile)) AS Percentagem,
(SELECT SUM(Filesize) FROM infofile) AS 'Total (KB)'
FROM infofile
GROUP BY Filetype
To have the SUM
as its own row..
SELECT NULL,
NULL,
SUM(Filesize)
FROM infofile
UNION ALL
SELECT Filetype,
((COUNT(Filetype) * 100) / (SELECT COUNT(*) FROM infofile)) AS Percentagem,
NULL AS 'Total (KB)'
FROM infofile
GROUP BY Filetype
The second query would output something like:
Filetype Percentagem Total (KB)
NULL NULL 7894561
1 10% NULL
2 20% NULL
3 30% NULL
4 40% NULL
Upvotes: 2
Reputation: 34
select Filetype,
(COUNT(Filetype) * 100 / (SELECT COUNT(*) FROM infofile)) AS 'Percentagem',
SUM(Filesize) AS 'Total (KB)'
FROM infofile
GROUP BY Filetype
Upvotes: 0