我有一个查询,它按以下结构顺序返回结果,按价格升序排列
SELECT our_price,
mrp,
marketplace_id,
test_id
FROM marketplace_test_mapping mtm
INNER JOIN marketplace m
ON m.id = mtm.marketplace_id
WHERE m.city_id = 1
AND mtm.test_id IN ( 36, 23, 43, 107,
121, 82 )
ORDER BY our_price ASC;
输出
our_price | mrp | marketplace_id | test_id
----------+-----+----------------+--------
50 90 3 23
51 70 2 23
52 88 1 23
53 80 3 24
54 90 2 24
55 90 4 23
56 90 1 25
57 90 2 25
58 90 1 24
我想为每个测试id取最低价格,但当我分组时 test_id
,它对 marketplace_id
以及返回以下内容
SELECT *
FROM (SELECT our_price,
mrp,
marketplace_id,
test_id
FROM marketplace_test_mapping mtm
INNER JOIN marketplace m
ON m.id = mtm.marketplace_id
WHERE m.city_id = 1
AND mtm.test_id IN ( 36, 23, 43, 107,
121, 82 )
ORDER BY our_price ASC) AS temp_marketplace_test_mapping
GROUP BY test_id;
实际产量
our_price | mrp | marketplace_id | test_id
----------+-----+----------------+--------
52 88 1 23
58 90 1 24
56 90 1 25
预期产量
our_price | mrp | marketplace_id | test_id
----------+-----+----------------+--------
50 90 3 23
53 90 3 24
56 90 1 25
两种结果的差别是 actual output
正在排序 marketplace_id
当按“开”分组时也是如此 test_id
.
3条答案
按热度按时间gajydyqb1#
“我想获取每个测试id的最低价格”
snvhrwxg2#
找到每个测试id的最低价格,然后得到市场id和mrp。
nmpmafwu3#