0

我正在使用 MySQL 和 PHP。

我尝试使用 bind_param 参数化查询。现在我需要将整数列表传递给参数化的 IN 查询。

我尝试过以下查询:

select id,date,
  sum(value) as distance ,
  (select number from table2 where id=id) as Number
from Table1 where id in (1777,1778,1779)

但它只返回列表中第一个值的结果(1777 ) 中第一个值的结果。

如何获得1777,1778,1779列表中所有条目 ( ) 的结果?

4

1 回答 1

0

你需要使用GROUP BY例如

SELECT 
    id, 
    date, 
    sum(value) as distance , 
    (SELECT number FROM table2 WHERE id=id) as Number 
FROM Table1 
WHERE 
    id in (1777,1778,1779) 
GROUP BY id

希望这可以帮助!

于 2014-09-09T12:02:23.907 回答