是否有任何sql子查询语法允许您从字面上定义临时表?
例如,像
SELECT MAX(count) AS max,COUNT(*) AS count FROM ( (1 AS id,7 AS count),(2,6),(3,13),(4,12),(5,9) ) AS mytable INNER JOIN someothertable ON someothertable.id=mytable.id
这将节省必须执行两个或三个查询:创建临时表,将数据放入其中,然后在连接中使用它.
解决方法
我想你可以用几个SELECT和UNIONs做一个子查询.
SELECT a,b,c,d FROM ( SELECT 1 AS a,2 AS b,3 AS c,4 AS d UNION ALL SELECT 5,6,7,8 ) AS temp;