如何从begning插入值 [英] how to insert the value from begning
本文介绍了如何从begning插入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张桌子差价
Checkin
结帐
现在我必须执行这两个查询....
Hi,
I have one table difference
Checkin
Checkout
now i have to execute this two query ....
INSERT INTO difference(CHECKIN) SELECT checktime from checkinout where sensorid='1'
INSERT INTO difference(CHECKOUT) SELECT checktime from checkinout where sensorid='2'
执行第一条查询记录后的样子。
Checkin Check out
--------- ---------
8/19/2013 14:53 Null
8/19/2013 16:46 Null
当我执行第二个querry它看起来像..
After executing the first query record look like.
Checkin Checkout
--------- ---------
8/19/2013 14:53 Null
8/19/2013 16:46 Null
and when i execute the second querry it look like..
Checkin Checkout
--------- ---------
8/19/2013 14:53 Null
8/19/2013 16:46 Null
NULL 8/19/2013 15:53
Null 8/19/2013 16:53
但我希望它是这样的...
but i want it to be like this...
Checkin Checkout
--------- ---------
8/19/2013 14:53 8/19/2013 15:53
8/19/2013 16:46 8/19/2013 16:53
..
plz help ...
..
plz help...
推荐答案
查看此示例
check this example
DECLARE @checkinout TABLE(in_time DATETIME, out_time DATETIME, senerio_id INT, u_id INT)
INSERT INTO @checkinout
SELECT * FROM
(
SELECT '2013-09-08 14:53' AS in_time, NULL AS out_time, 1 AS senerio_id, 1 AS u_id
UNION ALL
SELECT '2013-09-08 16:46' AS in_time, NULL AS out_time, 1 AS senerio_id, 2 AS u_id
UNION ALL
SELECT NULL AS in_time, '2013-09-08 15:53' AS out_time, 2 AS senerio_id, 1 AS u_id
UNION ALL
SELECT NULL AS in_time, '2013-09-08 16:53' AS out_time, 2 AS senerio_id, 2 AS u_id
) AS t
SELECT
u_id,
MAX(in_time) AS in_time,
MAX(out_time) AS out_time,
DATEDIFF(MI,MAX(in_time),
MAX(out_time)) AS diffInMinute
FROM @checkinout
GROUP BY u_id
快乐编码!
:)
Happy Coding!
:)
这篇关于如何从begning插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文