I have an SQL SELECT statement of the form:
SELECT a.date, a.count FROM (
SELECT d.date, x.count + y.count - z.count AS count
FROM date_table d
LEFT JOIN (
SELECT date, count FROM caluculated_table_x
) x ON d.date = x.date
LEFT JOIN (
SELECT date, count caluculated_table_y
) y ON d.date = y.date
LEFT JOIN (
SELECT date, count caluculated_table_z
) z ON d.date = z.date
) a ON a.date = d.date;
The SELECT works just fine, taking roughly 10s to complete. However, when I try to use it in a CREATE TABLE/UPDATE/INSERT INTO statement, e.g.:
CREATE TABLE count_summary
SELECT...;
I get "Error Code: 2013. Lost connection to MySQL server during query" after 600s. Any idea what might be causing this issue or how I might diagnose the problem?
CREATE TABLE t (<columns>); INSERT INTO t SELECT ...;instead of one? – ypercubeᵀᴹ Feb 16 '18 at 22:33CREATE TABLE ... SELECT ... ;– James Clubbe Feb 16 '18 at 22:36a.date = d.datecannot work becaused.dateis not visible outside there. – Rick James May 19 '18 at 01:11