见下面的查询。我想获得子查询中返回的表的大小,但.size不起作用。有办法解决这个问题吗?
SELECT
(SELECT
ROUND(AVG(ts.data / ts.avglen), 0) AS 'size'
FROM
x.ddp_table_stats AS ts, x.ddp_table_names AS tn
WHERE
ts.tableid = tn.id
AND ts.date = '2017-12-21'
AND tn.name IN ('nic_stat' , 'agent_app_names')
GROUP BY name).size -
(SELECT
ROUND(AVG(ts.data / ts.avglen), 0) AS 'size'
FROM
x.ddp_table_stats AS ts, x.ddp_table_names AS tn
WHERE
ts.tableid = tn.id
AND ts.date = '2017-12-19'
AND tn.name IN ('nic_stat' , 'agent_app_names')
GROUP BY name).size AS result;
答案 0 :(得分:0)
你实际上并不需要子查询。相反,我们可以使用条件聚合并对两个连接的表进行单次传递,以获得所需的结果。
SELECT
name,
ROUND(AVG(CASE WHEN ts.date = '2017-12-21' THEN ts.data / ts.avglen END) -
AVG(CASE WHEN ts.date = '2017-12-19' THEN ts.data / ts.avglen END), 0) AS size
FROM
ddp_table_stats AS ts
INNER JOIN ddp_table_names AS tn
ON ts.tableid = tn.id
WHERE
tn.name IN ('nic_stat' , 'agent_app_names')
GROUP BY
name;
请注意,我也选择了name
,因为选择我们分组的列通常是有意义的。另外,我用显式INNER JOIN
语法替换了隐式连接语法。
答案 1 :(得分:0)
@drawable/search
。
.size