【问题标题】:with cte union all select与 cte union all select
【发布时间】:2021-11-20 15:51:30
【问题描述】:

我有两张表 欠款发票 。 我正在尝试执行以下操作:

;with Acc.. as ( select ....from ....)

select ..... from  Arrears 

UNION ALL

select ... from Invoices 

问题是结果是这样的:

A header B header
row row
row row

输出应该是这样的:

Table B header c header
Arrays row row
Invoices row row

【问题讨论】:

    标签: sql common-table-expression union-all


    【解决方案1】:

    您可以在每个查询中添加一个字符串文字以指示它来自哪个表:

    SELECT 'Arrays' AS table_name, *
    FROM   arrays
    UNION ALL
    SELECT 'Invoices' AS table_name, *
    FROM   invoices
    

    【讨论】:

      猜你喜欢
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-08
      相关资源
      最近更新 更多