当我将下面的 UPDATE Query 放入 Workbench 时,它工作得很好,但是当我尝试通过 php 运行它时它什么也不做?有任何想法吗?
我已经尝试了表结构,TURNOVERSCORE
因为 varchar(100) 和 Float,table1.item 和 t2.item 是主键。
使用 mysql_error 时提供错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 2 行的 'UPDATE table1 JOIN (SELECT count(*) as cnt, ITEM FROM table2 WHERE' 附近使用正确的语法
$con = mysql_connect("localhost","username","pw");
$turnoverquery = "UPDATE table1
JOIN (SELECT count(*) as cnt, item FROM table2 WHERE table2.TRANS_DATE BETWEEN DATE_SUB(CURDATE(), INTERVAL 365 DAY) AND CURDATE() GROUP BY item) t2
ON table1.item = t2.item
SET table1.TURNOVERSCORE=CASE
WHEN t2.cnt/12 < 1 AND table1.CAT = 'E' THEN .05
WHEN t2.cnt/12 >= 1 AND t2.cnt/12 < 4 AND table1.CAT = 'E' THEN .5
WHEN (t2.cnt/12) >= 4 AND table1.CAT = 'E' THEN 1
WHEN (t2.cnt/12) <= 5 AND table1.CAT != 'E' THEN .05
WHEN (t2.cnt/12) >= 6 AND (t2.cnt/12) < 11 AND table1.CAT != 'E' THEN .25
WHEN (t2.cnt/12) >= 11 AND (t2.cnt/12) < 21 AND table1.CAT != 'E' THEN .5
WHEN (t2.cnt/12) >= 21 AND table1.CAT != 'E' THEN 1 END";
mysql_query($turnoverquery);