I have a table that contains dates, the table can have multiple dates in it. For Example
我有一个包含日期的表,这个表可以包含多个日期。例如
Date
'2011-01-01'
'2011-03-01'
'2011-06-01'
'2011-11-01'
'2011-12-01'
I also have a table that just has units in it. There will never be duplicate units.
我还有一个表格里面有单位。永远不会有重复的单位。
Unit
1
2
3
4
5
6
How do I return all dates for every unit. For example:
我如何返回每个单元的所有日期。例如:
Unit Date
1 '2011-01-01'
1 '2011-03-01'
1 '2011-06-01'
1 '2011-11-01'
1 '2011-12-01'
2 '2011-01-01'
2 '2011-03-01'
2 '2011-06-01'
2 '2011-11-01'
2 '2011-12-01'
and so on.....
等等.....
1 个解决方案
#1
5
Using CROSS JOIN
使用交叉连接
http://msdn.microsoft.com/en-us/library/ms190690.aspx
http://msdn.microsoft.com/en-us/library/ms190690.aspx
SELECT d.[Date]
,u.[Unit]
FROM [Date_Table] d
CROSS JOIN [Unit_Table] u
Query assumes Date
column is in Date_Table
, and Unit
column is in Unit_Table
查询假设日期列在Date_Table中,单元列在Unit_Table中
#1
5
Using CROSS JOIN
使用交叉连接
http://msdn.microsoft.com/en-us/library/ms190690.aspx
http://msdn.microsoft.com/en-us/library/ms190690.aspx
SELECT d.[Date]
,u.[Unit]
FROM [Date_Table] d
CROSS JOIN [Unit_Table] u
Query assumes Date
column is in Date_Table
, and Unit
column is in Unit_Table
查询假设日期列在Date_Table中,单元列在Unit_Table中