0

这是一个 mysql 问题,我什至不知道是否可能,但正如您在下面看到的,我有 2 个表。他们基本上都在做同样的事情,只是有所不同。一个已支付 = 1,另一个已支付 = 0

所以我很头疼的是,如果表 2 的cardidpricetitle与表 1 中包含的 pay = 1 一样精确,则它不能显示在表 #2 中。哦,只有在创建也匹配时才会进行比较,+ - 5分钟没问题。

sql语句1

SELECT t.cardid, ct.title, t.transactionid, FROM_UNIXTIME(t.created),t.priceafterdiscount, t.paid 
FROM transactions as t
left join exp_channel_titles ct on t.restaurant_id = ct.entry_id
where t.paid = 0 
and t.transactiontime > '2013-09-23' and 
t.phoneid != '123456789012345' and 
t.cardid != '88888888' and 
t.restaurant_id NOT in (47505) 
ORDER BY t.created DESC;

我对表 1 的输出。

Card_ID     Title               Trans_ID Created              price   Paid
10017039    Café Cici           15887   2013-09-26 11:04:49  75     0
10017039    Café Cici           15885   2013-09-26 11:03:08  100    0
10017039    Café Cici           15884   2013-09-26 11:02:33  15000  0
10166152    Viet-Nam Nam        15870   2013-09-25 20:51:44  28800  0
10030773    Restaurant Shezan   15866   2013-09-25 20:10:35  38175  0
10030773    Restaurant Shezan   15865   2013-09-25 20:09:41  50900  0
10030773    Restaurant Shezan   15864   2013-09-25 20:08:13  38175  0

sql语句2

SELECT t.cardid, ct.title, t.transactionid, FROM_UNIXTIME(t.created), t.priceafterdiscount, t.paid
FROM transactions as t
left join exp_channel_titles ct on t.restaurant_id = ct.entry_id
where t.paid = 1
and t.transactiontime > '2013-09-23' and 
t.phoneid != '123456789012345' and 
t.cardid != '88888888' and 
t.restaurant_id NOT in (47505) 
ORDER BY t.created DESC

我对表 2 的输出。

Card_ID     Title               Trans_ID Created              price   Paid
10171120    Hjørnet             15889   2013-09-26 11:18:47  6750    1
10017039    Café Cici           15888   2013-09-26 11:06:24  75      1
10017039    Café Cici           15886   2013-09-26 11:04:14  75      1
10129289    Café ZugarBaby      15876   2013-09-25 21:44:34  15000   1
10082903    Café Katz           15862   2013-09-25 19:40:26  19040   1
10064767    Restaurant Fønix    15857   2013-09-25 17:58:53  14250   1
4

1 回答 1

0

select * from table 1 where row is not in table 2 by your conditions:

select * from 
table1 
left join table2 
on table1.cardid=table2.cardid 
and table1.price=table2.price 
and table1.title=table2.title and 
timestampdiff(minute,table1.created, table2.created) between -5 and 5

where table2.cardid is null

或者,您可以合并所有两个查询,按卡片、价格、标题分组,并添加具有 count(*)=1 和paid=0 的条件,但它不适用于 5 分钟时间戳条件

于 2013-09-26T10:43:14.917 回答