如何使用LIKE
运算符进行字符串搜索,字符串将作为另一个select语句的输出?
SELECT CONCAT('"id":"',transactions.Id,'"') AS id
FROM transactions.transactions LEFT JOIN
report.PlayerTransaction
ON (transactions.Id=PlayerTransaction.TranId )
WHERE TranId IS NULL AND transactions.created_at > '2017-10-15' ;
SELECT *
FROM report.EtlServiceErrorLog
WHERE Topic = 'player' and ErrorSourceData like xxxx and
CreatedDate > '2017-10-15' ;
考虑这两个问题;我希望查询写成:
SELECT *
FROM report.EtlServiceErrorLog
WHERE Topic = 'player' and
ErrorSourceData like in (SELECT CONCAT('"id":"', transactions.Id, '"') AS id
FROM transactions.transactions LEFT JOIN
report.PlayerTransaction
ON (transactions.Id = PlayerTransaction.TranId ) WHERE TranId IS NULL AND transactions.created_at > '2017-10-15'
;) and
CreatedDate > '2017-10-15' ;
或者我必须得到循环的帮助吗?请给我举个例子。
答案 0 :(得分:1)
看来你真的想找
ErrorSourceData LIKE CONCAT('%"id":"', t.Id, '"%')
使用IN
无法做到这一点。您需要EXISTS
。
SELECT *
FROM report.EtlServiceErrorLog sel
WHERE Topic = 'player'
AND EXISTS
(
SELECT *
FROM transactions.transactions t
WHERE t.id NOT IN (SELECT pt.TranId FROM report.PlayerTransaction pt)
AND t.created_at > '2017-10-15'
AND sel.ErrorSourceData LIKE CONCAT('%"id":"', t.Id, '"%')
)
AND CreatedDate > '2017-10-15' ;
答案 1 :(得分:0)
如果子查询只返回1行,它将起作用。
答案 2 :(得分:0)
如果你不使用LIKE运营商'%' _改为IN ErrorSourceData in(SELECT CONCAT('" id":"',transactions.Id,'"')