Получив самую высокую цену

У меня есть запрос, который я написал для моего аукциона. Но проблема, с которой я сталкиваюсь, заключается в том, чтобы получить самую высокую цену за конкретный товар.

Ниже мой запрос:

$query = "SELECT  auctions.auctionId, quantity, startPrice, reservePrice, startTime,
endTime, itemName, itemBrand, itemDescription, items.image, auctions.views,
item_categories.categoryName as subCategoryName, superCategoryName,
item_categories.superCategoryId, item_categories.categoryId,
users.userId, users.firstName, users.lastName, bids.userId AS mbid,
conditionName, countryName, COUNT(DISTINCT (bids.bidId)) AS numBids,
COUNT(DISTINCT (auction_watches.watchId)) AS numWatches,
MAX(bids.bidPrice) AS highestBid, MAX(bids.bidPrice)as currentPrice,
case
when highestBidderId = bids.userId THEN true
else false
end as isUserWinning

FROM auctions

LEFT OUTER JOIN bids ON bids.auctionId = auctions.auctionId
LEFT OUTER JOIN auction_watches ON auction_watches.auctionId = auctions.auctionId
JOIN items ON items.itemId = auctions.itemId
JOIN users ON items.userId = users.userId
JOIN item_categories ON items.categoryId = item_categories.categoryId
JOIN super_item_categories ON  item_categories.superCategoryId = super_item_categories.superCategoryId
JOIN item_conditions ON items.conditionId = item_conditions.conditionId
JOIN countries ON users.countryId = countries.countryId

WHERE auctions.endTime > now() AND auctions.auctionId IN ( SELECT bids.auctionId
FROM bids where bids.userId = bids.userId GROUP BY bids.auctionId)
GROUP BY  auctions.auctionId,bids.userId
ORDER BY endTime ASC";

Теперь, если я использую это условие, чтобы определить самую высокую цену, я получаю

Перекупил, снова ставку, чтобы выиграть! для всех предметов.

if($row['endTime'] >= $now){
if($row['isUserWinning']){?>
<p class="alert-success" style="padding: 7px 7px; border-radius: 3px;">Currently the highest bidder!</p> <?php
}else{?>
<p class="alert-warning" style="padding: 7px 7px; border-radius: 3px;">Outbidded, bid again to win!</p> <?php
}
}

Что я делаю не так или как я могу это сделать?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector