我有以下观点,我需要从 Oracle 移植到 MySQL。这在 Oracle 中完美运行,但在 MySQL 中由于subquery cannot exist in a view
错误而无法运行。如何转换它以使其在 MySQL 中工作?如果我对此提出另一种看法,它将如何影响性能?可取吗?如果是这样,我该怎么做?如果第二个视图不是一个好主意,如何转换它?谢谢你的帮助!
CREATE OR REPLACE VIEW view_name (var1, var2, var3, var4, var5) AS
SELECT SUM(A.var1a) var1,
SUM(A.var2a) var2,
SUM(A.var3a) var3,
SUM(A.var4a) var4,
SUM(A.var5a) var5
FROM (SELECT CASE columnx when 'abc' then COUNT(E.ID) end var1a,
CASE columnx when 'def' then COUNT(E.ID) end var2a,
CASE columnx when 'ghi' then COUNT(E.ID) end var3a,
CASE columnx when 'jkl' then COUNT(E.ID) end var4a,
COUNT(E.ID) var5a
FROM <list of tables>
WHERE <set of conditions>
GROUP BY columnx) A;