Hello Stackoverflow成员,
我无法理解如何完成SQL查询。目前我们有两个完成交易的“结账”,然后我们监控每个交易的生产率。然而,最近我们创造了平均结账生产力(每小时)
问题是平均值只是添加两个条目而不是创建平均值。
SQL代码应该如下:
Checkout 1 : 25 transactions
Checkout 2 : 50 transactions
计算两者之间的平均值(每小时)= / 60 我认为我只能写2除以,显然如果只有一个结账工作,这将把1结账除以2。 因此应完成以下内容: 如果:只有一笔交易没有分开!
Checkout 1: 25 transactions
checkout 2: 0 transactions
目前我们有一些SQL代码可以一起添加,但不会对数据做任何其他事情。
我理解一个案例陈述会允许我这样做吗?
EDIT ----
((SELECT SUM(total_moves) from Checkouts.db.checkout.transaction_statistics
LEFT OUTER JOIN Checkouts.db.checkout_details ON checkout.transaction_statistics.vvd_gkey = checkout_details.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE flex_string01 = Transaction_id and short_name IN ('2.1', '2.2')) /
case when
(convert(decimal(12,2),(
((SELECT DATEDIFF(MINUTE,
( SELECT CASE WHEN
(SELECT MIN(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.to_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE to_pos_locid = Transaction_id
AND move_kind != 'Floor'
and short_name IN ('2.1', '2.2')
) <
( SELECT MIN(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.fm_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE fm_pos_locid = Transaction_id
AND move_kind != 'Floor'and short_name IN ('2.1', '2.2'))
THEN (SELECT MIN(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.to_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE to_pos_locid = Transaction_id
AND move_kind != 'Floor'and short_name IN ('2.1', '2.2')
) ELSE
( SELECT MIN(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.fm_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE fm_pos_locid = Transaction_id
AND move_kind != 'Floor' and short_name IN ('2.1', '2.2'))
END)
,
( SELECT CASE WHEN
(SELECT MAX(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.to_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE to_pos_locid = Transaction_id
AND move_kind != 'Floor'
and short_name IN ('2.1', '2.2')
) >
( SELECT MAX(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.fm_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE fm_pos_locid = Transaction_id
AND move_kind != 'Floor'and short_name IN ('2.1', '2.2'))
THEN (SELECT MAX(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.to_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE to_pos_locid = Transaction_id
AND move_kind != 'Floor'and short_name IN ('2.1', '2.2')
) ELSE
( SELECT MAX(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.fm_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE fm_pos_locid = Transaction_id
AND move_kind != 'Floor' and short_name IN ('2.1', '2.2'))
END)
) ) / 60 )))) = '0' THEN null else
(convert(decimal(12,2),(
((SELECT DATEDIFF(MINUTE,
( SELECT CASE WHEN
(SELECT MIN(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.to_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE to_pos_locid = Transaction_id
AND move_kind != 'Floor'
and short_name IN ('2.1', '2.2')
) <
( SELECT MIN(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.fm_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE fm_pos_locid = Transaction_id
AND move_kind != 'Floor'and short_name IN ('2.1', '2.2'))
THEN (SELECT MIN(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.to_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE to_pos_locid = Transaction_id
AND move_kind != 'Floor'and short_name IN ('2.1', '2.2')
) ELSE
( SELECT MIN(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.fm_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE fm_pos_locid = Transaction_id
AND move_kind != 'Floor' and short_name IN ('2.1', '2.2'))
END)
,
( SELECT CASE WHEN
(SELECT MAX(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.to_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE to_pos_locid = Transaction_id
AND move_kind != 'Floor'
and short_name IN ('2.1', '2.2')
) >
( SELECT MAX(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.fm_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE fm_pos_locid = Transaction_id
AND move_kind != 'Floor'and short_name IN ('2.1', '2.2'))
THEN (SELECT MAX(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.to_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE to_pos_locid = Transaction_id
AND move_kind != 'Floor'and short_name IN ('2.1', '2.2')
) ELSE
( SELECT MAX(Checkouts.db.inv_move_event.t_carry_complete)
FROM Checkouts.db.inv_move_event
INNER JOIN Checkouts.db.checkout_details ON Checkouts.db.inv_move_event.fm_pos_locid = flex_string01
INNER JOIN Checkouts.db.checkout.transaction_statistics ON checkout_details.vvd_gkey = checkout.transaction_statistics.vvd_gkey
INNER JOIN Checkouts.db.xps_che ON checkout_statistics.checkout_gkey = Checkouts.db.xps_che.gkey
WHERE fm_pos_locid = Transaction_id
AND move_kind != 'Floor' and short_name IN ('2.1', '2.2'))
END)
) ) / 60 ))))END
) AS [Average Checkout Productivity],
亲切的问候, 莱恩
答案 0 :(得分:0)
案例陈述可以检查结账是否已经解雇。
所以尝试这样的事情:
Select
case when Checkout1 <> 0 and Checkout2 <> 0 then divide else dosomthing
from yourtable
假设结帐结果在表格中