嗨,我有一个数据库,可以逐行存储票务详细信息。因此,例如,如果有人进来并使用优惠券购买服务并购买了礼品卡,它将将该交易分解为 3 个单独的表格条目......例如,如果我使用下面的查询搜索票号“m123”我得到下面的结果。
Select *
FROM TicketsDetails
WHERE (sTicket_Number = 'M123')
Ticket Description Amount
M123 BOGO 15
M123 Service 1 -15
M123 GC Service 1 15
M123 $5 OFF -5
当前查询和输出:
SELECT t1.sTicket_Number, t1.sDescription, t1.sUserName, t2.sDescription AS Second_description
FROM TicketsDetails AS t1 INNER JOIN
TicketsDetails AS t2 ON t1.sTicket_Number = t2.sTicket_Number
WHERE (t1.sDescription = '$5 OFF') AND (t2.sDescription = 'BOGO')
M100304 $5 OFF Kenny BOGO
M100304 $5 OFF Kenny BOGO
M100542 $5 OFF Kenny BOGO
M103706 $5 OFF Kenny BOGO
M132464 $5 OFF Dante BOGO
M132464 $5 OFF Dante BOGO
M132501 $5 OFF Dante BOGO
M132501 $5 OFF Dante BOGO
M132528 $5 OFF Dante BOGO
M133892 $5 OFF Raynon BOGO
M133892 $5 OFF Raynon BOGO
M134067 $5 OFF Raynon BOGO
M134067 $5 OFF Raynon BOGO
我想做的是退回任何带有“bogo”和“$ 5 off”描述的票号。这可能吗,因为它们是具有相同票号的单独条目?