我在报告工具中使用 mysql。我有一个临时表,我正在填写一些查询,然后显示临时表中的数据。
我的表结构是
Prim_key starttime endtime timediff
1 2012-07-20 00:00:0 2012-07-22 10:55:32 39332
2 2012-07-20 04:50:13 2012-07-22 10:55:32 158719
3 2012-07-20 10:00:00 2012-07-22 00:00:05 5
我需要显示一个时间百分比 < 30 ,介于 30-45 和 > 45 之间的表。我编写了以下查询,但出现状态 1137 错误 - 无法重新打开表:'t_results'
Expected result:
| % of less than 30 min | % of between 30 - 45 | % of greater than 45 mins |
查询是
SELECT prim_key key, (
SELECT count(*)*100 / (
SELECT count(*)
FROM t_results
WHERE timediff > 0 )
FROM t_results
WHERE (timediff /60) < 30
) less30, (
SELECT count(*)*100 / (
SELECT count(*)
FROM t_results
WHERE timediff > 0 )
FROM t_results
WHERE (timediff /60) >= 30 and (timediff /60) <= 45
) bet3045,
(SELECT count(*)*100 / (
SELECT count(*)
FROM t_results
WHERE timediff > 0 )
FROM t_results
WHERE (timediff /60) > 45
) great45
FROM t_results
WHERE 1 = 1 AND 1 =1
GROUP BY prim_key
有没有别的写法?