【发布时间】:2017-09-26 10:51:29
【问题描述】:
我有 3 个名为 Vendor、Customers 和 ReceivePayment 的表。在我的ReceivePayment 表中,我有名为PaymentType 和AccountID 的列。我想要的只是在ReceivePayment 表中使用AccountID 从供应商或客户表中选择数据,但我必须应用条件从客户表或供应商表中选择数据,条件将基于@987654335 的PaymentType 列@ 桌子。比如如果我在PaymentType 列中有“销售”,那么它应该从客户表中选择数据,或者如果我在 PaymentType 列中有“购买”,那么它应该从供应商表中选择数据。
我正在使用 case 语句,但我不知道如何在 case 语句的 THEN 子句中使用 Select 语句。
我正在尝试使用此代码
SELECT CASE ReceivePayment.PaymentType
WHEN 'Sale' THEN SELECT Name FROM Vendor WHERE VendorID = ReceivePayment.AccountID
WHEN 'Purchase' THEN SELECT Name FROM Customers WHERE CustID = ReceivePayment.AccountID
END
FROM ReceivePayment
【问题讨论】:
-
请编辑您的问题以添加sample data 和基于该数据的预期输出。以Formatted text 和严格的no screen shots 提供它们。 请勿在 cmets 中发布代码或其他信息。请确保您拥有minimal, complete and verifiable example。
-
(1) 用您正在使用的数据库标记您的问题。 (2) 显示您尝试过的查询(可能简化以关注您遇到问题的点)。正如所写,这个问题对其他人来说毫无意义。