显示最高价值的交易

Displaying highest valued transaction

我想编写一个查询来显示有关进行最高交易的客户的所有信息。预计新创建的到期金额列用于标识最高交易

Top Table is my Customer table and the bottom table is the Transaction table

最高的交易是由 Ken 完成的,但我必须编写一个查询来显示他来自客户的整行 table,仅此而已

我认为这对你有用:

select c.CustomerID, c.FirstName, c.LastName, c.Addrass, c.PostCode, c.Email, c.DOB
from CustomerTable as c, TransactionTable as t
where c.CustomerID = t.CustomerID
AND Amount_Due = (select Max(Amount_Due) from TransactionTable)

我会推荐 order bytop:

select c.*, t.*
from customer c
inner join (select top (1) with ties * from transaction t order by amount_due desc) t 
    on t.customerid = c.customerid

子查询选择具有最大 amount_due 的事务(如果有平局,则保留它们)。然后我们可以加入客户 table.