2014-04-18 39 views
0

我有以下代码联合两个选择语句,但第二个选择开始选择2.这是什么?select 2在联合sql语句中的含义是什么?

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

+6

它在行tax_type'等于设置''到2'由第二个子查询返回。 –

回答

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' | 
+------------ 
+0

感谢您的快速响应。 – michaelc35

相关问题