我有以下数据的两张表:
1)Trans Table
TICKET STATUS
56 0
56 0
2)Resa Table
R_TICKET R_STATUS
56 0
如果表格中的票证数与之匹配,那么我想要这样的结果,然后打印0
其他1
。
我已经尝试了以下查询,但它不起作用
select case when count(a.ticket) = count(b.r_ticket)
then 0
else 1
end as result
from trans a, resa b
它会显示0
,但它应为1
,因为56
中的2
点数在trans
中为1
而在resa
中为TICKET Count(Ticket) r_Ticket Count(r_Ticket) result
56 2 56 1 1
58 1 58 1 0
}}
有些问题有所改变: 我想要这样的结果:
expression: term opt_add
opt_add: '+' term opt_add
| /* empty */
term: factor opt_mul
opt_mul: '*' factor opt_mul
| /* emtpty */
factor: number
| '(' expression ')
答案 0 :(得分:0)
请勿在{{1}}子句中使用逗号。无论如何,在这种情况下这是错误的。 。 。如果其中一个表为空,那么您将在聚合之前获得一个空的中间结果集。
相反,使用子查询来获取计数:
consec = []
for key, group in groupby(enumerate(a), lambda i: i[0] - i[1]):
consec.append(list(map(itemgetter(1), group)))
consecHead = consec[0]
consecTail = consec[-1]
if 1 in consecHead:
consecHeadcheck = consecHead
else:
consecHeadcheck = []
if 21 in consecTail:
consecTailcheck = consecTail
else:
consecTailcheck = []
b_prior = [x for x in polPos if x not in consecTailcheck]
b = [x for x in b_prior if x not in consecHeadcheck]
print(b)
c = []
for i in range(len(b)):
if int(int(b[i+1]) - int(b[i])) !=1:
c.append(int(b[i+1]) - int(b[i])
print(c)
答案 1 :(得分:0)
SELECT COALESCE(t1.ticket, t2.ticket),
CASE WHEN t1.count = t2.count THEN 0 ELSE 1 END AS match
FROM
(
SELECT TICKET AS ticket, COUNT(*) AS tcount
FROM Trans
GROUP BY TICKET
) t1
FULL OUTER JOIN
(
SELECT R_TICKET AS ticket, COUNT(*) AS tcount
FROM Resa
GROUP BY R_TICKET
) t2
ON t1.ticket = t2.ticket