An SQL statement that runs directly into MySQL is normal.
But the result of running this SQL with PHP mysql_query is different, will it be the reason why mysql_query cannot parse?
SQL 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.reg ION,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 are 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, ' 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
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, ' 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
This is not allowed.
But MySQL is able to perform normally to get results.
PHP can also execute, but the result is offset!!
The question is not whether there is grammatical error
But the control logic is the cyclic paradox.
But I think that there should be no logical problem ah, first find out the results. Then write the results to yourself.
The most important is that the results of PHP run different from the results of MySQL run!!
is to try to avoid this logic, or else there will be such unexpected results.
INSERT into a (version) SELECT version from a WHERE id=1;
Assuming that the first execution inserts 1 strips
Then the second execution will insert 2.
The third execution will insert 4.
I know...................................