1

我正在为一个班级建立一个婚礼数据库,目前有一个费用表。该表显示费用标签(鲜花、摄影师、乐队......)和付款到期日(除其他外)。我还有一张单独的桌子用于其他任务(询问新娘派对,发送邀请......)。

我目前有一个联合查询,它将两个表组合成一个“待办事项列表”。这是查询的sql:

SELECT Expense AS Task, DateDue, tblExpenses.[Paid?] AS [Completed?]
from tblExpenses
UNION SELECT Task, DateDue, tblToDoList.[Completed?]
from tblToDoList;

我的问题是按计划组合的最终列表,但该列表在“任务”标题下具有诸如“鲜花”之类的值。我希望能够在来自费用表的值之前添加“支付”或“已支付”,以便它读起来像谓词而不是主题。有没有办法做到这一点?

抱歉,如果这有任何令人困惑的地方。我对 SQL 的了解非常有限,我不确定如何准确地表达所有内容。

4

1 回答 1

0

怎么样 .. ?

SELECT Expense AS Task, DateDue, 
       IIf(tblExpenses.[Paid?]=True,"Paid","Pay For") AS [Completed?]
FROM tblExpenses
UNION 
SELECT Task, DateDue, tblToDoList.[Completed?]
FROM tblToDoList;

如果paid 为真(是),查询将返回“Paid”,否则将返回“Pay for”。

重新评论

SELECT "Paid " & Expense AS Task, DateDue, 
       tblExpenses.[Paid?] AS [Completed?]
FROM tblExpenses
UNION 
SELECT Task, DateDue, tblToDoList.[Completed?]
FROM tblToDoList;
于 2013-02-22T20:51:44.267 回答