合并查询结果 [英] Combine results of queries
问题描述
嗯,我正在尝试完成一个有点复杂的查询,但我尝试用文字解释,然后我和你分享查询伙计。
-第一栏 - 显示一些文件的类型(.exe,.pdf,......)
-Second column - 显示数据库中该文件的百分比
-Third列(这里是问题出现的地方) - 应该显示每种类型文件的大小,然后低于总数。
这是这个查询的输出而没有给我每种类型文件的大小
文件类型|百分比|总计(KB)
.pdf 25% 25
.dll 45% 300
170
这是我的疑问:
SELECT 文件类型,
((COUNT(文件类型)* 100 )/ ( SELECT COUNT(*) FROM infofile)) AS 百分比,
NULL AS ' 总计(KB)'
FROM infofile
GROUP BY 文件类型
UNION ALL
SELECT NULL ,
NULL ,
SUM(Filesize)
FROM infofile
我想要的是Total(KB)列中每个Filetype的大小。
感谢您的帮助。祝你有美好的一天
我尝试过的事情:
我'我试图模拟添加另一个实际工作但与主查询无关的选择。
SELECT文件类型,SUM(文件大小)AS'总计(KB)'
FROM infofile
GROUP BY Filetype
你可以试试这个
SELECT id,代码,
( SELECT SUM(id) AS sumid
FROM tbl_wtr
WHERE (accid = newtb。 id)) AS sumid
FROM
( SELECT id,代码
FROM tbl_stacc) AS newtb
Hey hey guys!
Well, I am trying to finish a query that is a little bit complex, but I try in the begging to explain with words and then I share the query with you guys.
-First column - shows me the type of some file(.exe, .pdf, ...)
-Second column - shows me the percentage of that file on the database
-Third column(Here it's where the problem comes) - should show me the size of every type of file and then below the total.
This is the output with this query without giving me the size of each type of files
Filetype | Percentagem | Total (KB)
.pdf 25% 25
.dll 45% 300
170
This is my query:
SELECT Filetype,
((COUNT(Filetype) * 100) / (SELECT COUNT(*) FROM infofile)) AS Percentagem,
NULL AS 'Total (KB)'
FROM infofile
GROUP BY Filetype
UNION ALL
SELECT NULL,
NULL,
SUM(Filesize)
FROM infofile
What I want to get to is the size of each Filetype in the Total(KB) column.
Thank you for your help. Have a great day
What I have tried:
I've tried to simulate adding another select that actually works but independent from the main query.
SELECT Filetype, SUM(Filesize) AS 'Total(KB)'
FROM infofile
GROUP BY Filetype
hi you can try this
SELECT id, code, (SELECT SUM(id) AS sumid FROM tbl_wtr WHERE (accid = newtb.id)) AS sumid FROM (SELECT id, code FROM tbl_stacc) AS newtb
这篇关于合并查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!