select 2在union sql语句中意味着什么



我有下面的代码,它合并了两个select语句,但第二个select以select 2开头。这是干什么的?

select tax_type, sum(amount) from bill_tax_tbl a (index multi), bill_summ_tbl b where a.customer_no = @customer_no and a.invoice_month = convert(tinyint,datepart(mm,dateadd(mm,-1,convert(datetime,@date)))) and a.job = b.job and a.billing_sub_job = b.billing_sub_job and b.job_group is null group by tax_type union select 2, sum(amount) from bill_tax_tbl a (index multi), bill_summ_tbl b where a.customer_no = @customer_no and tax_type = 1 and a.invoice_month = convert(tinyint,datepart(mm,dateadd(mm,-1,convert(datetime,@date)))) and a.job = b.job and a.billing_sub_job = b.billing_sub_job and b.job_group is null

2是一个值常量,最终会出现在tax_type字段中。

示例给定表格:

+-----+-----+
|  a  |  b  |
+===========+
| 'a' | 'b' |
| 'c' | 'd' |
+------------

查询人:

SELECT a, b from table
UNION
SELECT 'y','z'

将返回:

+-----+-----+
|  a  |  b  |
+===========+
| 'a' | 'b' |
| 'c' | 'd' |
| 'y' | 'z' |
+------------

相关内容

最新更新