create table tmp as select code,avg(how-low)/low as vol from quote group by code;
select avg(vol) from tmp
我用第一个语句创建一个新表,然后从tmp table中选择ave(vol)。如何将两个sqlite语句组合成一个语句?
答案 0 :(得分:1)
如果您以后不需要临时表,请使用common table expression:
WITH tmp AS (SELECT avg(how-low)/low AS vol
FROM quote
GROUP BY code)
SELECT avg(vol)
FROM tmp
如果你有一个过时的SQLite版本(早于3.8.3),你可以使用子查询:
SELECT avg(vol)
FROM (SELECT avg(how-low)/low AS vol
FROM quote
GROUP BY code)