问题是获取<md-input-container [hideRequiredMarker]="true">
status = '404 NOT FOUND'
查询结果
SELECT CAST(time AS DATE) as day, status, count(*),
count(*) * 100.0 / (
SELECT count(*) FROM log
GROUP BY CAST(time AS DATE)
HAVING CAST(time AS DATE) = '2016-07-17'
) as percent
FROM log L
GROUP BY day, status
HAVING status = '404 NOT FOUND'
ORDER BY percent DESC
我不想让day | status | count | percent
---------------------------------------------------------------
2016-07-17 | 404 NOT FOUND | 1267 | 2.2650481792016018
2016-07-24 | 404 NOT FOUND | 429 | 0.76693422957970574039
2016-07-05 | 404 NOT FOUND | 425 | 0.75978332767220265656
2016-07-19 | 404 NOT FOUND | 422 | 0.75442015124157534369
2016-07-21 | 404 NOT FOUND | 419 | 0.74905697481094803082
2016-07-08 | 404 NOT FOUND | 416 | 0.74369379838032071795
2016-07-06 | 404 NOT FOUND | 414 | 0.74011834742656917604
2016-07-09 | 404 NOT FOUND | 410 | 0.73296744551906609221
硬编码,而是想在外部查询中传递2016-07-17
的值,即day
像这样:
L.day
这样做
SELECT CAST(time AS DATE) as day, status, count(*),
count(*) * 100.0 / (
SELECT count(*)FROM log
GROUP BY CAST(time AS DATE)
HAVING CAST(time AS DATE) = L.day
) as percent
FROM log L
GROUP BY day, status
HAVING status = '404 NOT FOUND'
ORDER BY percent DESC
更新:根据评论
ERROR: column l.day does not exist
LINE 5: HAVING CAST(time AS DATE) = L.day
^
同样的结果。
答案 0 :(得分:1)
您无法在定义的同一级别访问别名,您需要使用= cast(l.time as date)
。
但是那个条款并没有真正意义 - 至少对我而言
我认为你想要的是:
SELECT CAST(time AS DATE) as day,
status,
count(*),
count(*) * 100.0 / (SELECT count(*)
FROM log l2
where cast(l2.time as date) = CAST(l.time AS DATE)) as percent
FROM log L
GROUP BY day, status
HAVING status = '404 NOT FOUND'
ORDER BY percent DESC;