如何使用 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' ;
或者我必须获得循环的帮助吗?请给我举个例子。
最佳答案
看来你真的很想找
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' ;
关于mysql - 我们可以使用 like 运算符并选择查询作为其输入吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47180132/