我是新来的 ksql
并且一直在使用mysql
最长的时间。
我想知道无论如何在 KSQL
中有子查询?
这个查询没有任何问题:
SELECT a.executedate, count(a.pno), sum(a.amount) FROM
tb3_withdraw_record_summary a WHERE a.status='3' GROUP BY
a.executedate;
而此查询返回错误消息:
SELECT a.executedate, count(a.pno), sum(a.amount), (SELECT COUNT(b.pno)
FROM tb3_withdraw_record_summary b WHERE b.status='5' AND
b.executedate = a.executedate) FROM tb3_withdraw_record_summary a
WHERE a.status='3' GROUP BY a.executedate
'Failed to prepare statement: 'B' is not a valid stream/table name or alias. Caused by: 'B' is not a valid stream/table name or alias.'
无论如何让我完成这项工作?谢谢!
最佳答案
Ksql 目前不支持嵌套查询功能,但您可以通过以下方式进行 -
1) CREATE STREAM B AS SELECT COUNT(b.pno)
FROM tb3_withdraw_record_summary b WHERE b.status='5';
2) SELECT a.executedate, count(a.pno), sum(a.amount) FROM tb3_withdraw_record_summary a JOIN B within 5 hours ON b.executedate = a.executedate WHERE a.status='3' GROUP BY a.executedate
请记住,连接与关系数据库世界的含义非常不同,这里的数据通过多个存储桶中的键进行分区,并且在概念上是“共置”连接。更多详情time-window这里。
希望它会有所帮助。
关于apache-kafka - 我可以在 KSQL 中编写子查询吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55098337/