我正在查看收据订单项详细信息,并且由于其中包含的条件而导致排除特定交易的问题。我有一个事务,它在事务中排除了项目,我需要在我的数据中排除整个事务。例如:
Transaction_id void_ind
1 2 1430 12/20/2017 5066 3 2.37 614 N
1 2 1430 12/20/2017 5066 3 2.37 614 N
1 2 1430 12/20/2017 5066 3 2.37 614 N
1 2 1430 12/20/2017 5066 3 2.37 614 N
1 2 1430 12/20/2017 5066 3 2.37 614 Y
1 2 1430 12/20/2017 5066 3 2.37 614 Y
1 2 1430 12/20/2017 5066 3 2.37 614 Y
1 2 1430 12/20/2017 5066 3 2.37 614 N
1 2 1430 12/20/2017 5066 3 2.37 614 Y
1 2 1430 12/20/2017 5066 3 2.37 614 N
1 2 1430 12/20/2017 5066 3 2.37 614 Y
交易编号为5066,每行是收据上的特定项目。 Y和N显示该项目是否无效。
我需要做的是从我的数据中排除整个交易。我包含的标题是正确的字段名称。
现在是SQL:
SELECT BIGPDATAVIEW_TRANSACTION_HEADER.transaction_type_cd,
BIGPDATAVIEW_TRANSACTION_HEADER.transaction_status_cd,
BIGPDATAVIEW_TRANSACTION_HEADER.location_id,
BIGPDATAVIEW_TRANSACTION_HEADER.transaction_dt,
BIGPDATAVIEW_TRANSACTION_HEADER.transaction_id,
BIGPDATAVIEW_TRANSACTION_HEADER.workstation_id,
BIGPDATAVIEW_TRANSACTION_TOTAL.total_transaction_amt,
BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_duration_nbr,
BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM.void_ind
FROM ((BIGPDATAVIEW_TRANSACTION_HEADER
INNER JOIN BIGPDATAVIEW_RETAIL_TRANSACTION ON (BIGPDATAVIEW_TRANSACTION_HEADER.location_id = BIGPDATAVIEW_RETAIL_TRANSACTION.location_id)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.transaction_dt = BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_dt)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.transaction_id = BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_id)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.workstation_id = BIGPDATAVIEW_RETAIL_TRANSACTION.workstation_id))
INNER JOIN BIGPDATAVIEW_TRANSACTION_TOTAL ON (BIGPDATAVIEW_TRANSACTION_HEADER.location_id = BIGPDATAVIEW_TRANSACTION_TOTAL.location_id)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.transaction_dt = BIGPDATAVIEW_TRANSACTION_TOTAL.transaction_dt)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.transaction_id = BIGPDATAVIEW_TRANSACTION_TOTAL.transaction_id)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.workstation_id = BIGPDATAVIEW_TRANSACTION_TOTAL.workstation_id))
INNER JOIN BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM ON (BIGPDATAVIEW_RETAIL_TRANSACTION.location_id = BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM.location_id)
AND (BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_dt = BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM.transaction_dt)
AND (BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_id = BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM.transaction_id)
AND (BIGPDATAVIEW_RETAIL_TRANSACTION.workstation_id = BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM.workstation_id)
WHERE (((BIGPDATAVIEW_TRANSACTION_HEADER.transaction_type_cd)="1")
AND ((BIGPDATAVIEW_TRANSACTION_HEADER.transaction_status_cd)="2")
AND ((BIGPDATAVIEW_TRANSACTION_HEADER.location_id)=1430)
AND ((BIGPDATAVIEW_TRANSACTION_HEADER.transaction_dt)=#12/20/2017#)
AND ((BIGPDATAVIEW_TRANSACTION_HEADER.transaction_id)=5066)
AND ((BIGPDATAVIEW_TRANSACTION_TOTAL.total_transaction_amt)>0
AND (BIGPDATAVIEW_TRANSACTION_TOTAL.total_transaction_amt)<10)
AND ((BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_duration_nbr)>500));
如果有人可以提供帮助,那将会有所帮助。提前谢谢。
答案 0 :(得分:0)
由于您的某个条件规定交易ID必须为5066,因此您没有看到任何结果。您必须删除该条件,并排除要在条件中排除的交易的ID号。
试试这个:
SELECT BIGPDATAVIEW_TRANSACTION_HEADER.transaction_type_cd,
BIGPDATAVIEW_TRANSACTION_HEADER.transaction_status_cd,
BIGPDATAVIEW_TRANSACTION_HEADER.location_id,
BIGPDATAVIEW_TRANSACTION_HEADER.transaction_dt,
BIGPDATAVIEW_TRANSACTION_HEADER.transaction_id,
BIGPDATAVIEW_TRANSACTION_HEADER.workstation_id,
BIGPDATAVIEW_TRANSACTION_TOTAL.total_transaction_amt,
BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_duration_nbr,
BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM.void_ind
FROM ((BIGPDATAVIEW_TRANSACTION_HEADER
INNER JOIN BIGPDATAVIEW_RETAIL_TRANSACTION ON (BIGPDATAVIEW_TRANSACTION_HEADER.location_id = BIGPDATAVIEW_RETAIL_TRANSACTION.location_id)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.transaction_dt = BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_dt)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.transaction_id = BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_id)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.workstation_id = BIGPDATAVIEW_RETAIL_TRANSACTION.workstation_id))
INNER JOIN BIGPDATAVIEW_TRANSACTION_TOTAL ON (BIGPDATAVIEW_TRANSACTION_HEADER.location_id = BIGPDATAVIEW_TRANSACTION_TOTAL.location_id)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.transaction_dt = BIGPDATAVIEW_TRANSACTION_TOTAL.transaction_dt)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.transaction_id = BIGPDATAVIEW_TRANSACTION_TOTAL.transaction_id)
AND (BIGPDATAVIEW_TRANSACTION_HEADER.workstation_id = BIGPDATAVIEW_TRANSACTION_TOTAL.workstation_id))
INNER JOIN BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM ON (BIGPDATAVIEW_RETAIL_TRANSACTION.location_id = BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM.location_id)
AND (BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_dt = BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM.transaction_dt)
AND (BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_id = BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM.transaction_id)
AND (BIGPDATAVIEW_RETAIL_TRANSACTION.workstation_id = BIGPDATAVIEW_RETAIL_TRANSACTION_LINE_ITEM.workstation_id)
WHERE (((BIGPDATAVIEW_TRANSACTION_HEADER.transaction_type_cd)="1")
AND ((BIGPDATAVIEW_TRANSACTION_HEADER.transaction_status_cd)="2")
AND ((BIGPDATAVIEW_TRANSACTION_HEADER.location_id)=1430)
AND ((BIGPDATAVIEW_TRANSACTION_HEADER.transaction_dt)=#12/20/2017#)
'This is the line you have to take out:
'AND ((BIGPDATAVIEW_TRANSACTION_HEADER.transaction_id)=5066)
AND ((BIGPDATAVIEW_TRANSACTION_TOTAL.total_transaction_amt)>0
AND (BIGPDATAVIEW_TRANSACTION_TOTAL.total_transaction_amt)<10)
AND ((BIGPDATAVIEW_RETAIL_TRANSACTION.transaction_duration_nbr)>500)
'This is the line you will need to put in:
AND BIGPDATAVIEW_TRANSACTION_HEADER.transaction_id NOT IN(5066));
我在WHERE子句的末尾添加了'Not In'条件。如果您希望将来有另一个要排除的交易,您可以在括号中添加其他数字。如:
NOT IN(5066, 5099, 3048)
如果有帮助,请告诉我。
答案 1 :(得分:0)
例如:
5206 20-Dec-17 8885 1 $ 8.40 906 N
5206 20-Dec-17 8885 1 $ 8.40 906 N
5206 20-Dec-17 8885 1 $ 8.40 906 N
5206 20-Dec-17 8885 1 $ 8.40 906 N
5195 20-Dec-17 209 3 $ 3.98 599 Y
5195 20-Dec-17 209 3 $ 3.98 599 N
5195 20-Dec-17 209 3 $ 3.98 599 N
5195 20-Dec-17 209 3 $ 3.98 599 N
5195 20-Dec-17 209 3 $ 3.98 599 N
5195 20-Dec-17 209 3 $ 3.98 599 N
5181 20-Dec-17 8689 2 $ 6.48 654 N
5181 20-Dec-17 8689 2 $ 6.48 654 N
我的数据需要包括商店5206 Transaction_id 8885和商店5181 Transaction_id 8689.我需要排除商店5195和交易209,因为它在同一交易中显示Y和N.希望这是我的数据看起来更好的例子。这只是我数据的一个示例