我也有類似的表下面SQL Server 2005中SQL Server查詢內部聯接查詢不起作用
date_column | field1 | field2
1 June 2012 | xyz | 53
1 June 2012 | abc | 87
2 June 2012 | xyz | 81
3 June 2012 | xyz | 54
3 June 2012 | abc | 53
3 June 2012 | abc | 54
4 June 2012 | mmn | 53
4 June 2012 | xyz | 54
4 June 2012 | mmn | 54
4 June 2012 | mmn | 55
3 June 2012 | abc | 55
3 June 2012 | adf | 86
3 June 2012 | asd | 33
我想找到具有相應FIELD2值「53」,「54」所有的字段1的值和'55'。同日起這樣的輸出應該如下:
date_column | field1 | field2
3 June 2012 | abc | 53
3 June 2012 | abc | 54
3 June 2012 | abc | 55
4 June 2012 | mmn | 53
4 June 2012 | mmn | 54
4 June 2012 | mmn | 55
我想下面的SQL代碼內加入,但它不工作
select date_column, field1, field2 from table1
inner join (select date_column, field1, field2 from table1 where field2
in ('54', '55')) as table2
on table1.date_column = table2.date_column and
table1.field1 = table2.field1
where field1 in ('53', '54', '55')
group by date_column, field1, field2
order by date_column, field1, field2
它是如何不工作? –
你是否得到一個含糊不清的列錯誤? – HLGEM