SELECT `bid_amount`,`valid_until`, min('bid_amount') as `lowest_bid`
`cf1`.`country_name` AS `country_from`, `rq`.`city_from`,
`cf2`.`country_name` AS `country_to`, `rq`.`city_to`,
`sub_cat`.`sub_cat_name`,
`cat`.`cat_name`
FROM `bids`
JOIN `request_quote` `rq` ON `bids`.`bid_for` = `rq`.`quoteid`
JOIN `countries` `cf1` ON `rq`.`country_from` = `cf1`.`country_id`
JOIN `countries` `cf2` ON `rq`.`country_to` = `cf2`.`country_id`
LEFT JOIN `cat` ON `rq`.`cat` = `cat`.`cat_id`
LEFT JOIN `sub_cat` ON `rq`.`sub_cat` = `sub_cat`.`sub_cat_id`
WHERE `bids`.`bid_by` = $bidderId GROUP BY `bids`.`bid_amount`
所以我正在开发这种拍卖网站。我需要返回的是特定用户的所有出价,此外还有一些关于每个出价的额外信息。
我想要的一条信息是每件商品的最低出价。所以这里是出价表。'bid_for` 引用出价的项目。所以我想得到由“where bid_for = x”引用的'min(bid_amount)'。但正如您在最后一行中看到的,我已经有 WHERE 子句通过用户 ID 引用它。
所以简而言之,是否有选择一个(或多个)由不同“where”子句引用的信息而不是查询的其余部分?(如果这有意义的话)
+--------+--------+---------+------------+-------------+---------------+-------------+
| bid_id | bid_by | bid_for | bid_amount | pickup_date | delivery_date | valid_until |
+--------+--------+---------+------------+-------------+---------------+-------------+
| 1 | 24 | 2 | 19.99 | 2013-06-01 | 2013-06-01 | 2013-06-01 |
| 2 | 27 | 2 | 25.00 | 2013-06-01 | 2013-06-01 | 2013-06-01 |
+--------+--------+---------+------------+-------------+---------------+-------------+