3

我需要选择字段messageusername从表列表中选择list_id=1(可以是 2 或 5 等)且具有最小数值(min(number))。我该怎么做?我尝试过这个:

SELECT `message`,`username` FROM `list` WHERE `list_id`=2 AND min(`number`)

但它不起作用。

4

2 回答 2

4

试试看

SELECT `message`,`username`
FROM `list`
WHERE `list_id` = 2
ORDER BY `number` ASC
LIMIT 1
于 2012-12-23T18:12:05.593 回答
0
SELECT 
    a.*
FROM list
INNER JOIN   (
     SELECT 
          `message`,
          `username`,
          MIN(`number`) 
     FROM `list` 
     WHERE `list_id`=2 
    ) as a on a.id = list.id
于 2012-12-23T18:14:35.250 回答