我的php / mysql技能很差。 我有这张桌子:
id|ball1|ball2|ball3|ball4|prize|
|1| 2| 5| 10| 4| 0|
|2| 5| 9| 4| 1| 0|
|3| 3| 6| 4| 9| 0|
|4| 4| 8| 2| 3| 0|
|5| 8| 9| 4| 10| 0|
|6| 2| 4| 1| 10| 0|
使用此查询:
$g1=GetRow("SELECT id
, GROUP_CONCAT(ball ORDER BY ball) balls
FROM
( SELECT id,ball1 ball FROM lottery
UNION
SELECT id,ball2 ball FROM lottery
UNION
SELECT id,ball3 ball FROM lottery
UNION
SELECT id,ball4 ball FROM lottery
) x
WHERE ball IN (2,5,10,4)
GROUP
BY id
HAVING COUNT(*) >= 3");
我得到了这个输出:
1 - 2,4,5,10
6 - 2,4,10
我想将collen“prize”更新为1,其中count> = 3 我试过这个:
$sql=sqlQuery("UPDATE lottery set prize=1 where g1=1");
没用。 试过这个:
GetRow("UPDATE lottery set premio=1 where ball ORDER BY ball) balls
FROM
( SELECT id,ball1 ball FROM lottery
UNION
SELECT id,ball2 ball FROM lottery
UNION
SELECT id,ball3 ball FROM lottery
UNION
SELECT id,ball4 ball FROM lottery
) x
WHERE ball IN (2,5,10,4)
GROUP
BY id
HAVING COUNT(*) >= 3");
也没用。 THX。
答案 0 :(得分:0)
你能试试吗?
UPDATE lottery set prize = '1' where premio = '1' and
IF(ball1 IN(2,5,10,4),1,0)+
IF(ball2 IN(2,5,10,4),1,0)+
IF(ball3 IN(2,5,10,4),1,0)+
IF(ball4 IN(2,5,10,4),1,0) >= 3
远比使用更新和选择一样复杂。