Using variables in SQL queries
In the last section, we learned how to connect filters to saved questions written in SQL. However, to do so, we needed to use the notebook editor as an intermediary step. It would not have worked had we written the question in pure SQL. Let's see for ourselves, by recreating the Count of Menu Items Ordered question in pure SQL:
- Open up the Items Ordered question we saved earlier.
- Click the diagonal arrows to expand the editor.
- Edit the SQL as follows:
SELECT c.name , SUM(item_count) as items_ordered FROM ( SELECT * , CAST(single_item_orders->>'id_menu' AS INT) as id_menu , CAST(single_item_orders->>'count' AS INT) as item_count FROM ( SELECT * &...