-1

こんにちは!

これはおそらくSQLエキスパートにとっては簡単な質問です。私が持っているテーブルは次のとおりです。

**Table1 (Users):**
UserId -> 0,1,2...
UserName -> name1, name2, name3 ...

**Table2 (Actions):**
DealId -> 80,81,82...
BuyerId -> 0,1,2...
SellerId -> 2,3,4...
Amount -> 80,120,900...

**Table3 (Deals):**
DealId -> 80,81,82...
Dealname -> DealName1,DealName2...
UserId -> 0,1,2...

そして、これが私が必要とする結果のテーブルです(3つのテーブルから):

Column 1: Buyer Name(Users.UserName) with (Actions.BuyerId -> Users.UserId)
Column 2: Seller Name(Users.UserName) with (Actions.SellerId -> Users.UserId)
column 3: Deal Name(Deals.DealName) with (Deals.DealId -> 80 [known number])
column 4: Amount (Actions.Amount) with (Deals.DealId -> 80 [known number])

もちろん、正しいDealId(80)の結果のみを表示する必要があります。誰でもお手伝いできますか?

はっきりしているといいのですが。

ありがとうございました!!

エラン。

4

2 に答える 2

7
 SELECT [Buyer].UserName, 
        [Seller].UserName, 
        [Deals].Dealname, 
        [Actions].Amount 
 FROM [Deals]
 LEFT JOIN [Actions] ON [Actions].DealID = [Deals].DealID
 LEFT JOIN [Users] AS [Seller] ON [Seller].UserID = [Actions].SellerID
 LEFT JOIN [Users] AS [Buyer] ON [Buyer].UserID = [Actions].BuyerId
 WHERE [Deals].DealID = 80
于 2012-10-29T18:38:22.907 に答える
1
SELECT Buyer.UsernName, Seller.UserName, Deals.Dealname, Action.Amount FROM Deals
LEFT JOIN Actions ON Actions.DealID=Deals.DealID
LEFT JOIN Users AS Seller ON Seller.UserID=Actions.UserID
LEFT JOIN Users AS Buyer ON Buyer.UserID=Buyer.UserID
WHERE Deals.DealID=80
于 2012-10-29T18:30:36.607 に答える