![](/img/trans.png)
[英]How to retrieve data for two different portions of a single web page using LINQ from the same database table?
[英]Getting two different values for same atribute from a single table in SQL
我有三張桌子,也就是。 投標(bid_id,base_price),Customer(customer_id,name ..)和Customer_Bid(customer_id,bid_id,bidding_amount),其中客戶出價及其出價金額存儲在Customer_Bid表中。 我想顯示客戶的詳細信息以及他的出價ID,以及出價最高的客戶。
我試圖獲取客戶詳細信息,但我無法在同一張表中顯示他的出價金額以及最高出價金額。
請任何人可以幫助我。 謝謝。
編輯這是注釋中的查詢
select cb.bid_id, c.customer_id ,MyBid=cb.total_bidding_ammount
, HighestBid= max(cb.total_bidding_ammount)
from customer as c
,customer_bidding as cb
,bid as b
group by cb.bid_id, c.customer_id, cb.total_bidding_ammount
如果您更改此設置:
, HighestBid= max(cb.total_bidding_ammount)
像這樣:
, HighestBid =
(select max(bidding_ammount)
from customer_bidding
where bid_id = bid.bid_id)
你會在正確的軌道。
試試這個:
SELECT cb.bid_id,
c.customer_id,
cb.total_bidding_ammount,
topbids.customer_id as topbid_customer_id,
topbid
FROM customer c
INNER JOIN customer_bidding as cb
ON c.customer_id = cb.customer_id
INNER JOIN (
SELECT cb.bid_id, c.customer_id, MAX(cb.total_bidding_ammount) as topbid
FROM customer c
INNER JOIN customer_bidding cb
ON (c.customer_id = cb.customer_id)
GROUP BY cb.bid_id
) topbids
ON cb.bid_id = topbids.bid_id
select a.*, b.bidding_amount,
e.bidding_amount as highest_bid
from customer a
inner join customer_bid b on a.customer_id = b.customer_id
inner join bids c on b.bid_id = c.bid_id
join
(select * from (
select bidding_amount,bid_id
from customer_bid
order by bidding_amount desc
) d group by d.bid_id) e on b.bid_id = e.bid_id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.