我已经写了这个查询,但是它说每个表都需要有自己的别名。我究竟做错了什么?据我所知,我已经对表进行了别名。
SELECT (a.total_complete_days / b.total_days) * 100 AS "% of complete days"
FROM
(SELECT COUNT(*) AS total_complete_days
FROM (
SELECT email, job_date, SUM(job_minutes)
FROM jobs
GROUP BY email, job_date
HAVING SUM(job_minutes) BETWEEN 200 and 1000
) a,
(SELECT COUNT(*) AS total_days
FROM (
SELECT email, job_date, SUM(job_minutes)
FROM jobs
GROUP BY email, job_date
) b)
答案 0 :(得分:1)
我想您可以将查询简化为
SELECT
(COUNT(CASE WHEN t.job_minutes_sum BETWEEN 200 and 1000 THEN 1 ELSE NULL END) / COUNT(*)
) * 100 AS "% of complete days"
FROM (
SELECT email, job_date, SUM(job_minutes) job_minutes_sum
FROM jobs
GROUP BY email, job_date
) t