我使用SUM&amp ;;进行MYSQL查询CROSS JOIN,工作正常。
MYSQL QUERY:
SELECT SUM(totexec/(pass_count+fail_count))/d.total COUNT FROM test_schedule CROSS JOIN ( SELECT COUNT(*) total FROM test_schedule WHERE project='JupiterQA' ) d WHERE project='JupiterQA'
但是我试图在MSSQL中执行相同的查询,显示“列'd.total'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。”
之后我在查询结尾处添加了GROUP BY a.total, 错误是: 除以遇到的零错误。
我在所有表中都有记录,查询是错误的吗?
答案 0 :(得分:0)
我不问你为什么使用交叉连接:D 只需在查询中添加group by子句
SELECT SUM(totexec(pass_count+fail_count))d.total COUNT FROM test_schedule CROSS JOIN ( SELECT COUNT(*) total FROM test_schedule WHERE project='JupiterQA' ) d WHERE project='JupiterQA' GROUP BY d.total
答案 1 :(得分:0)
这应该等同于MYSQL查询:
SELECT tSum / dTotal AS COUNT
FROM (
SELECT SUM(totexec / (pass_count+fail_count)) AS tSum, d.total AS dTotal
FROM test_schedule
CROSS JOIN ( SELECT COUNT(*) total
FROM test_schedule
WHERE project='JupiterQA' ) d
WHERE project='JupiterQA' ) t
我认为不需要CROSS JOIN
。这也应该做的工作:
SELECT tSum / ( SELECT COUNT(*)
FROM test_schedule
WHERE project='JupiterQA' ) AS COUNT
FROM (
SELECT SUM(totexec / (pass_count+fail_count)) AS tSum
FROM test_schedule
WHERE project='JupiterQA' ) t