我有兩個看起來像這樣的表:
客戶資訊:

租金資訊:

我想顯示客戶表的所有詳細資訊,但只顯示當前正在租用的客戶。我已經嘗試過,但在 sql 上沒有任何成功。
uj5u.com熱心網友回復:
我認為您可能正在查看可能只是一個簡單的內部聯接和 Where 查詢,也就是說,如果您能夠使用 SQL/T-SQL。
SELECT c.CustomerID, c.CustomerName
FROM CustomerInformation c
INNER JOIN RentInformation r ON r.CustomerID = c.CustomerID
WHERE r.endDate > GetDate()
uj5u.com熱心網友回復:
有多種方法可以實作這一目標
select c.* from customer_information c inner join rent_information r on r.customerId = c.customerId and r.endDate > now();
如果您只想要獨特的結果,請使用它
select c.* from customer_information c inner join rent_information r on r.customerId = c.customerId and r.endDate > now() group by c.customerId;
如果您想在大型資料集上運行這些查詢,您可能想查看子查詢的使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/468354.html
下一篇:反透視訪問資料表
