我正在制作工厂转移报告:
在我的申请中,我提供了一个用于选择班次和工厂的下拉列表,他们将从日历中选择一个日期
我有3班
我有一个名为datalogging的表,其中将存储登录信息,如下所示:
Name Shiftname operatorname Date plantname line Machine
Pradeepa Shift2(11-7) Operator 3 2011-05-28 Plant 3 Line5 mc10
Ashwini Shift1(7-3) Operator 1 2011-05-29 Plant 3 Line6 mc12
Deepika Shift2(11-7) Operator 3 2011-05-29 Plant 5 Line9 mc18
Ashwini Shift1(7-3) Operator 1 2011-05-24 Plant 1 Line1 mc1
Deepika Shift2(3-11) Operator 2 2011-05-24 Plant 2 Line3 mc5
Ashwini Shift2(3-11) Operator 2 2011-05-25 Plant 2 Line3 mc5
依旧......
我有一个参数表,如温度,压力,pH值,速度,二氧化碳等
温度表包含以下数据,此表将包含从早上7点到凌晨3点的所有读数
这是温度表读数
Temperature Time Date
27 1900-01-01 13:46:37.000 2011-06-07 00:00:00
27.3 1900-01-01 13:51:37.000 2011-06-07 00:00:00
27.6 1900-01-01 13:56:37.000 2011-06-07 00:00:00
27.9 1900-01-01 14:01:37.000 2011-06-07 00:00:00
28.2 1900-01-01 14:06:37.000 2011-06-07 00:00:00
28.5 1900-01-01 14:11:37.000 2011-06-07 00:00:00
28.8 1900-01-01 14:16:37.000 2011-06-07 00:00:00
27 1900-01-01 15:09:52.000 2011-06-07 00:00:00
27.3 1900-01-01 15:11:52.000 2011-06-07 00:00:00
27.6 1900-01-01 15:13:53.000 2011-06-07 00:00:00
27.9 1900-01-01 15:15:52.000 2011-06-07 00:00:00
28.2 1900-01-01 15:17:52.000 2011-06-07 00:00:00
28.5 1900-01-01 15:19:52.000 2011-06-07 00:00:00
28.8 1900-01-01 15:21:52.000 2011-06-07 00:00:00
29.1 1900-01-01 15:23:52.000 2011-06-07 00:00:00
29.4 1900-01-01 15:25:52.000 2011-06-07 00:00:00
29.7 1900-01-01 15:27:52.000 2011-06-07 00:00:00
30 1900-01-01 15:29:52.000 2011-06-07 00:00:00
30.3 1900-01-01 07:03:10.000 2011-06-07 00:00:00
30.6 1900-01-01 07:05:11.000 2011-06-07 00:00:00
30.9 1900-01-01 07:07:10.000 2011-06-07 00:00:00
31.2 1900-01-01 07:09:10.000 2011-06-07 00:00:00
31.5 1900-01-01 07:11:10.000 2011-06-07 00:00:00
31.8 1900-01-01 07:13:11.000 2011-06-07 00:00:00
31.8 1900-01-01 07:15:11.000 2011-06-07 00:00:00
32.1 1900-01-01 07:17:10.000 2011-06-07 00:00:00
32.4 1900-01-01 07:19:10.000 2011-06-07 00:00:00
32.7 1900-01-01 07:21:10.000 2011-06-07 00:00:00
33 1900-01-01 07:23:11.000 2011-06-07 00:00:00
27 1900-01-01 09:03:10.000 2011-06-07 00:00:00
27.3 1900-01-01 09:05:09.000 2011-06-07 00:00:00
27.6 1900-01-01 09:07:09.000 2011-06-07 00:00:00
27.9 1900-01-01 09:09:09.000 2011-06-07 00:00:00
28.2 1900-01-01 09:11:09.000 2011-06-07 00:00:00
28.5 1900-01-01 09:13:09.000 2011-06-07 00:00:00
28.8 1900-01-01 09:15:09.000 2011-06-07 00:00:00
29.1 1900-01-01 09:17:09.000 2011-06-07 00:00:00
29.4 1900-01-01 09:19:10.000 2011-06-07 00:00:00
29.4 1900-01-01 09:21:09.000 2011-06-07 00:00:00
29.7 1900-01-01 09:23:09.000 2011-06-07 00:00:00
30 1900-01-01 09:25:09.000 2011-06-07 00:00:00
30.3 1900-01-01 09:27:09.000 2011-06-07 00:00:00
27 1900-01-01 10:33:10.000 2011-06-07 00:00:00
27.3 1900-01-01 10:35:10.000 2011-06-07 00:00:00
27.6 1900-01-01 10:37:10.000 2011-06-07 00:00:00
27.9 1900-01-01 10:39:10.000 2011-06-07 00:00:00
28.2 1900-01-01 10:41:10.000 2011-06-07 00:00:00
这是我的压力读数
Pressure Time Date
0.5 1900-01-01 13:46:36.000 2011-06-07 00:00:00
0.9 1900-01-01 13:51:36.000 2011-06-07 00:00:00
1.3 1900-01-01 13:56:36.000 2011-06-07 00:00:00
1.7 1900-01-01 14:01:36.000 2011-06-07 00:00:00
2.1 1900-01-01 14:06:36.000 2011-06-07 00:00:00
2.5 1900-01-01 14:11:36.000 2011-06-07 00:00:00
2.9 1900-01-01 14:16:36.000 2011-06-07 00:00:00
0.5 1900-01-01 15:09:52.000 2011-06-07 00:00:00
0.9 1900-01-01 15:11:51.000 2011-06-07 00:00:00
1.3 1900-01-01 15:13:52.000 2011-06-07 00:00:00
1.7 1900-01-01 15:15:52.000 2011-06-07 00:00:00
2.1 1900-01-01 15:17:51.000 2011-06-07 00:00:00
2.5 1900-01-01 15:19:51.000 2011-06-07 00:00:00
2.9 1900-01-01 15:21:51.000 2011-06-07 00:00:00
3.3 1900-01-01 15:23:51.000 2011-06-07 00:00:00
3.7 1900-01-01 15:25:51.000 2011-06-07 00:00:00
4.1 1900-01-01 15:27:51.000 2011-06-07 00:00:00
4.5 1900-01-01 15:29:51.000 2011-06-07 00:00:00
4.9 1900-01-01 07:03:09.000 2011-06-07 00:00:00
5.3 1900-01-01 07:05:09.000 2011-06-07 00:00:00
5.7 1900-01-01 07:07:09.000 2011-06-07 00:00:00
6.1 1900-01-01 07:09:09.000 2011-06-07 00:00:00
6.5 1900-01-01 07:11:09.000 2011-06-07 00:00:00
6.9 1900-01-01 07:13:09.000 2011-06-07 00:00:00
6.9 1900-01-01 07:15:09.000 2011-06-07 00:00:00
7.3 1900-01-01 07:17:09.000 2011-06-07 00:00:00
7.7 1900-01-01 07:19:09.000 2011-06-07 00:00:00
8.1 1900-01-01 07:21:09.000 2011-06-07 00:00:00
8.5 1900-01-01 07:23:09.000 2011-06-07 00:00:00
0.5 1900-01-01 09:03:09.000 2011-06-07 00:00:00
0.9 1900-01-01 09:05:09.000 2011-06-07 00:00:00
1.3 1900-01-01 09:07:09.000 2011-06-07 00:00:00
1.7 1900-01-01 09:09:09.000 2011-06-07 00:00:00
2.1 1900-01-01 09:11:09.000 2011-06-07 00:00:00
2.5 1900-01-01 09:13:09.000 2011-06-07 00:00:00
2.9 1900-01-01 09:15:09.000 2011-06-07 00:00:00
3.3 1900-01-01 09:17:09.000 2011-06-07 00:00:00
3.3 1900-01-01 09:19:09.000 2011-06-07 00:00:00
3.7 1900-01-01 09:21:09.000 2011-06-07 00:00:00
4.1 1900-01-01 09:23:09.000 2011-06-07 00:00:00
4.5 1900-01-01 09:25:09.000 2011-06-07 00:00:00
4.9 1900-01-01 09:27:09.000 2011-06-07 00:00:00
0.5 1900-01-01 10:33:10.000 2011-06-07 00:00:00
0.9 1900-01-01 10:35:10.000 2011-06-07 00:00:00
1.3 1900-01-01 10:37:10.000 2011-06-07 00:00:00
1.7 1900-01-01 10:39:10.000 2011-06-07 00:00:00
2.1 1900-01-01 10:41:10.000 2011-06-07 00:00:00
2.5 1900-01-01 17:02:57.000 2011-06-07 00:00:00
2.9 1900-01-01 17:04:57.000 2011-06-07 00:00:00
3.3 1900-01-01 17:06:57.000 2011-06-07 00:00:00
3.7 1900-01-01 17:08:57.000 2011-06-07 00:00:00
4.1 1900-01-01 17:10:57.000 2011-06-07 00:00:00
4.5 1900-01-01 17:12:57.000 2011-06-07 00:00:00
4.9 1900-01-01 17:14:57.000 2011-06-07 00:00:00
依旧......
用户将从下拉列表中选择一行并切换,他将从日历中选择日期如果用户选择shift1,工厂1和日期07/06/2011应显示上午7点到下午3点之间的读数在我的报告中
我的报告应如下所示:
Machine Shiftname Date Time Temperature Pressure
mc1 Shift1 2011/06/07 07:03:10.000 30.3 4.9
mc1 Shift1 2011/06/07 07:05:11.000 30.6 5.3
mc1 Shift1 2011/06/07 07:07:10.000 30.9 5.7
像这样我希望从7到3点的所有读数来自温度,压力,pH,二氧化碳,d02
任何人都可以帮助我。
答案 0 :(得分:0)
Select
DL.Machine,
DL.ShiftName,
@MyDate,
case when T.Time is null then P.Time else T.Time end as Time,
T.Temperature,
NULL as Pressure
From
DataLogging as DL
inner join Temperature as T on "reading time is within this shift's timespan"
Where
DL.Date = @MyDate
and DL.ShiftName = @MyShiftName
UNION
Select
DL.Machine,
DL.ShiftName,
@MyDate,
case when T.Time is null then P.Time else T.Time end as Time,
NULL as Temperature,
P.Pressure
From
DataLogging as DL
inner join Pressure as P on "reading time is within this shift's timespan"
Where
DL.Date = @MyDate
and DL.ShiftName = @MyShiftName
让我在这里解释一下方法......
从DataLogging开始。您关心的是有特定班次的员工。您可以通过指定输入DATE并输入SHIFT在WHERE
子句中定义该员工。
加入Temperature
表格,因为您希望查看该人员班次的所有温度读数。
加入Pressure
表格,因为您希望看到该人员轮班的所有压力读数。
为什么我们UNION
?好吧,主要是为了防止欺骗(如果我们在同一个Select语句中加入两个读数表,则会存在Dupes)。正如您所注意到的,由于它们具有不同的时间戳,因此很难加入温度读数和压力读数。如果他们相隔一秒钟,那么没有什么可以加入的。因此,我认为最好的解决方案就是按照上面的说法简单地记录每次阅读。以上将首先列出所有温度读数,然后列出所有压力读数 - 并将它们组合到通过UNION
返回的相同表中。
注意:您可能应该使用datetime
字段而不是Date
列和时间列,因为它会将日期和时间存储在一个领域。
注意:您可以将那些具有相同日期和读数的读数组合在一起。通过在时间上使用子查询和grouping subquery来确定时间。
注意: "reading time is within this shift's timespan"
包含在上面,表示您需要填写的代码。您可能希望使用case语句来调整{{1}仅包含具有特定班次的项目
<强>参考强>