我见过类似的问题,但无法完全找到解决此问题的方法。忍受乱七八糟的桌子,问题应该是什么?非常坦率的。
我有下表。
LDTime Value
2013-07-24 00:00:00.000 14.85
2013-07-24 00:00:00.000 1.339
2013-07-24 00:15:00.000 95.9
2013-07-24 00:15:00.000 1.285
2013-07-24 00:30:00.000 160
2013-07-24 00:30:00.000 0.952
第 1、3 和 5 行是一种数据。2、4 和 6 是另一种类型。我有以下查询可以根据过滤条件检索类型:
SELECT
A.LDTime, A.Value As AValue
FROM
Table7 G
INNER JOIN
Table1 A
INNER JOIN
Table2 B ON A.DataSetIdx = B.DataSetIdx
INNER JOIN
Table3 C ON B.RetrievalIdx = C.RetrievalIdx ON G.ActionIdx = C.ActionIdx
INNER JOIN
Table4 D ON G.SpatialRefIdx = D.SpatialRefIdx
INNER JOIN
Table5 E
INNER JOIN
Table6 F ON E.StationIdx = F.StationIDx ON D.SpatialRefIdx = E.SpatialRefIdx
WHERE
F.StationIDx = 1
AND A.ParameterIdx = 18
AND A.LDTime BETWEEN '2013-7-24' AND '2013-7-25'
ORDER
BY A.LDTime
SELECT
A.LDTime, A.Value As BValue
FROM
Table7 G
INNER JOIN
Table1 A
INNER JOIN
Table2 B ON A.DataSetIdx = B.DataSetIdx
INNER JOIN
Table3 C ON B.RetrievalIdx = C.RetrievalIdx ON G.ActionIdx = C.ActionIdx
INNER JOIN
Table4 D ON G.SpatialRefIdx = D.SpatialRefIdx
INNER JOIN
Table5 E
INNER JOIN
Table6 F ON E.StationIdx = F.StationIDx ON D.SpatialRefIdx = E.SpatialRefIdx
WHERE
F.StationIDx = 1
AND A.ParameterIdx = 19
AND A.LDTime BETWEEN '2013-7-24' AND '2013-7-25'
ORDER BY
A.LDTime
请注意,我ParameterIdx
在两个查询之间只更改了一个过滤器变量 ( ),它区分了 value 列中存储的数据类型。
如何组合查询以生成一个结果集?(或者,我正在使用存储过程,所以这可以在多个查询中完成)。
LDTime AValue BValue
2013-07-24 00:00:00.000 14.85 1.339
2013-07-24 00:15:00.000 95.9 1.285
2013-07-24 00:30:00.000 160 0.952