我有这个查询,它基于一些与INNER JOIN
.
目前我有一个WHERE
条款,它一次提取一个 id。但是我怎样才能让它列出所有的ID呢?
我GROUP BY
在不同的地方尝试过,但无法弄清楚。
到目前为止,我的查询如下:
SELECT
equipment_id,
service_duration,
available_duration,
(available_duration / service_duration)*100 AS availability
FROM (
SELECT
SUM(service_end_time - service_start_time) AS service_duration
FROM(
SELECT equipment_id,
(CASE
END) AS service_start_time,
(CASE
END) AS service_end_time
FROM t1
WHERE equipment_id = 'EX123'
)AS A
) AS B
JOIN(
SELECT equipment_id,
SUM(available_end_time - available_start_time) AS available_duration
FROM (
SELECT equipment_id,
(CASE
END) AS available_start_time,
(CASE
END) AS available_end_time
FROM t2
WHERE equipment_id = 'EX123'
) AS C
) AS D
ON equipment_id=D.equipment_id
我想要做的是WHERE
用 a 替换子句GROUP BY
以列出所有 id 或类似的,但是让它工作超出了我的技能水平......非常感谢任何帮助:)