SELECT TOP 15
us.MxitId AS TransactionCreatedBy, COUNT(t.CreatedBy) Total
FROM [User] us
INNER JOIN [Transaction] t ON t.CreatedBy = us.UserId
Where ChildGender = 'Male'
GROUP BY us.MxitId, t.ChildGender
ORDER BY 2 desc
SELECT TOP 15
us.MxitId AS TransactionCreatedBy, COUNT(t.CreatedBy) Total
FROM [User] us
INNER JOIN [Transaction] t ON t.CreatedBy = us.UserId
Where ChildGender = 'Female'
GROUP BY us.MxitId, t.ChildGender
ORDER BY 2 desc
我想將上述兩個過程合併爲一個。將兩個內部連接查詢組合成一個過程
請任何人都可以幫助我,我得到的us.MxitId
列的重複值。
Select us.MxitId AS TransactionCreatedBy,
(SELECT TOP 15
COUNT(t.CreatedBy) TotalMale where ChildGender = 'Male') ,
(Select top 15 COUNT(t.CreatedBy) TotalFemale where ChildGender = 'Female')
FROM [User] us
INNER JOIN [Transaction] t ON t.CreatedBy = us.UserId
GROUP BY us.MxitId, t.ChildGender
ORDER BY 2 desc
你想怎樣把它們結合起來?男孩前15名用戶可能與女孩前15名用戶完全不同。或者,它們可以是相同的列表,但順序不同。告訴我們你想要輸出的樣子。 – Anon
嗨用戶是相同的兩種情況下,我想說如果用戶沒有記錄任何女性數據0,或反之亦然 – vini