我想编写一个查询来显示有关进行最高交易的客户的所有信息。预计使用新创建的到期金额列来标识最高交易
Top Table is my Customer table and the bottom table is the Transaction table
最高交易是由 Ken 进行的,但我必须编写一个查询,显示他从客户表中的整行,而没有其他内容
答案 0 :(得分:0)
我会推荐 order by
和 top
:
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
最大的事务(如果有关系,则保留)。然后我们可以将其与客户表连接起来。
答案 1 :(得分:-1)
我认为这对你有用:
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)