合并两个与GROUP BY相同的查询?

时间:2016-11-22 15:46:04

标签: sql merge group-by equals

正如标题所暗示的,我对两个查询具有相同的确切结构,但我只需要更改分组。我知道我可以做一个联合,但是,为了缩小脚本,有没有办法在一个查询中将两个分组关联起来?例如:

SELECT shtuff FROM report_tickets WHERE something = something GROUP BY companies

//查询两个

SELECT shtuff FROM report_tickets WHERE something = something GROUP BY ticket_id

我可以吗?:

SELECT * FROM report_tickets WHERE something = something GROUP BY companies AND ticket_id

我知道这不起作用,但在概念上。查询是否考虑了两个分组? ^^

我需要在下面的链接代码中添加以下内容到第30行,这可能会确定它是否可以正常工作。

SUM(IF(ROUND((SELECT difference)) < 1, 1, 0)) AS zero_to_one,
SUM(IF(ROUND((SELECT difference)) BETWEEN 1 AND 8, 1, 0)) AS one_to_eight,
SUM(IF(ROUND((SELECT difference)) BETWEEN 8 AND 24, 1, 0)) AS eight_to_twentyfour,
SUM(IF(ROUND((SELECT difference)) > 24, 1, 0)) AS over_twentyfour,

0 个答案:

没有答案