我的查询如下:
SELECT MAX(x.id) as id,
x.name, x.timestamp, x.balance
FROM sheet x
JOIN
(SELECT p.name,MAX(id) AS max_id, p.rate
FROM sheet p GROUP BY p.name) y
ON y.max_id = x.id
GROUP BY x.name
以动态方式查询仅IN的名称的最佳做法是:
array= ['flake', 'shane', 'klar']
我用不同状态的join()尝试了类似的事情:
WHERE x.name IN (' + array.join() + ')
答案 0 :(得分:0)
尝试一下:
SELECT MAX(x.id) as id,x.name,x.timestamp,x.balance FROM sheet x JOIN (SELECT p.name,MAX(id) AS max_id,p.rate FROM sheet p GROUP BY p.name) y ON y.max_id = x.id WHERE x.name IN ('flake', 'shane', 'klar') GROUP BY x.name