我有以下代码,它们联合两个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
答案 0 :(得分:4)
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' |
+------------