0

我有下表:

table_a
id | charge
1  |   95 
1  |   1
2  |   25

我想从每个 id 中选择最低费用并确定它是否小于...例如 SELECT id,charge FROM table_a WHERE MIN(charge) > 10 GROUP BY id

Results:
None

SELECT id,charge FROM table_a WHERE MIN(charge) < 10 GROUP BY id

Results:
id | charge
1  |   1
4

3 回答 3

0

似乎这应该有效,除非我遗漏了一些东西:

SELECT id, MIN(charge)
WHERE charge BETWEEN 10 AND 40
GROUP BY id
于 2013-07-16T19:45:33.473 回答
0

您不能在子句中使用聚合函数WHERE-它必须在HAVING子句中-但在您的情况下,您正在过滤行级值而不是聚合,所以这样的事情应该可以解决问题:

SELECT id, MIN(charge)
FROM table_a
WHERE charge BETWEEN 10 AND 40
GROUP BY id
于 2013-07-16T19:46:30.030 回答
0

你想使用having子句:

SELECT id, min(charge)
FROM table_a
group by id
having MIN(charge) < 10
于 2013-07-16T19:51:39.950 回答