0

我的表结构是这样的:

country                 | price  | code
---------------------------------------
EGYPT PROPER  WHOLESALE | 0.037  | 20
EGYPT FIXED             | 0.0710 | 20
EGYPT-OTHER             | .0497  | 20

我必须使用 GROUP BY 代码,我希望输出为:

country                 | price  | code
---------------------------------------
EGYPT PROPER  WHOLESALE | 0.037  | 20

具有价格的最小值。

我的查询是:

select MIN(inp.price) as Price, inp.code, inp.country
from tbl_input_values as inp 
GROUP BY code

但我得到的输出为:

country         | price | code
------------------------------
EGYPT-OTHER     | .037  | 20
4

4 回答 4

2

这里,

SELECT  *
FROM    tbl_input_values
WHERE   price = (SELECT MIN(PRICE) FROM tbl_input_values)
于 2013-01-28T15:07:21.677 回答
1

这将显示每个代码具有最低价格的行:

SELECT yourtable.*
FROM yourtable
WHERE (code, price) IN (select code, min(price)
                        from yourtable
                        group by code)
于 2013-01-28T15:13:04.067 回答
1

有多个代码:

SELECT tb1.* 
FROM tbl_input_values tb1
INNER JOIN (select code, min(price) minPrice
            FROM tbl_input_values
            GROUP BY code) as a
   ON a.code = tb1.code and a.minPrice =tb1.price
于 2013-01-28T15:15:53.470 回答
0

我认为最简单的方法是:

select t.*
from t
order by price
limit 1

你根本不需要聚合。

于 2013-01-28T15:14:11.793 回答