That's why ksqlDB exists and handles all that for you, turning streams into tables that you can query.
Otherwise loading data into a real database/data warehouse and using ETL with triggers/views/aggregations is better if you need advanced querying rather than a simple stream to table transforms.