Mysql_query () cannot parse an SQL statement normally, and it is normal to directly run it in mysql.
However, if mysql_query in php is used to run the SQL statement, the result is different. Is it because mysql_query cannot be parsed?
The SQL statement is as follows:
INSERT INTO analysis.caomei_of_list_pvuv (region,isp,uv,pv,date) SELECTtb2.region,tb2.isp,tb2.uv,tb2.pv,'2014-05-14' AS date FROM (SELECT tb.region,tb.isp, COUNT(tb.mac) AS uv,SUM(tb.mac_num) AS pv FROM caomei_20140515.caomei_1 AS tb WHERE tb.date = '2014-05-14' GROUP BY tb.region, tb.isp ) AS tb2 LEFT JOIN (SELECT tb6.region,tb6.isp,tb6.uv,tb6.pv FROM analysis.caomei_of_list_pvuv AS tb6 WHERE tb6.date='2014-05-14' ) AS tb1 ON tb2.region = tb1.region WHERE tb1.region IS NULL AND tb2.region IS NOT NULL ;
Reply to discussion (solution)
Nsert into analysis. caomei_of_list_pvuv
(Region, isp, uv, pv, date)
SELECT
Tb2.region, tb2.isp, tb2.uv, tb2.pv, '2017-05-14 'AS date
FROM
(
SELECT
Tb. region, tb. isp, COUNT (tb. mac) AS uv,
SUM (tb. mac_num) AS pv
FROM
Caomei_20140515.caomei_1 AS tb
WHERE
Tb. date = '2017-05-14'
Group by tb. region, tb. isp
) AS tb2
LEFT JOIN
(
SELECT
Tb6.region, tb6.isp, tb6.uv, tb6.pv
FROM
Analysis. caomei_of_list_pvuv AS tb6
WHERE
Tb6.date = '2017-05-14'
) AS tb1
ON tb2.region = tb1.region
WHERE
Tb1.region IS NULL
AND tb2.region IS NOT NULL
This is not allowed
Nsert into analysis. caomei_of_list_pvuv
(Region, isp, uv, pv, date)
SELECT
Tb2.region, tb2.isp, tb2.uv, tb2.pv, '2017-05-14 'AS date
FROM
(
SELECT
Tb. region, tb. isp, COUNT (tb. mac) AS uv,
SUM (tb. mac_num) AS pv
FROM
Caomei_20140515.caomei_1 AS tb
WHERE
Tb. date = '2017-05-14'
Group by tb. region, tb. isp
) AS tb2
LEFT JOIN
(
SELECT
Tb6.region, tb6.isp, tb6.uv, tb6.pv
FROM
Analysis. caomei_of_list_pvuv AS tb6
WHERE
Tb6.date = '2017-05-14'
) AS tb1
ON tb2.region = tb1.region
WHERE
Tb1.region IS NULL
AND tb2.region IS NOT NULL
This is not allowed
However, mysql runs normally to obtain results.
Php can also be executed, but the result shows an offset !!
The question is not whether there is a syntax error.
Control logic is a cyclical paradox.
But I think there should be no logic problem. First, check the results. Then write the result to yourself.
The results of php running are different from those of mysql running !!
Do you want to avoid this logic as much as possible? otherwise, this unexpected result will appear.
INSERT INTO a (version)SELECT version FROM a WHERE id=1;
Assume that one entry is inserted during the first execution.
The second execution inserts two
The third execution inserts four
I understand ...................................