{R} RawQL

RAWQL / LOCAL SQL WITH DUCKDB

Query CSV files with SQL

Answer a concrete question from two exports: how much revenue came from paid orders, and which customer segment placed them?

RawQL is in invite-only beta. These guides and sample files are public. You need beta access to run the examples in the editor.

Download and import the examples

Save orders.csv and customers.csv. They contain fictional data. In RawQL, open Databases → Data files and import both. The views are named orders_csv and customers_csv.

The orders file has six rows with order_id, customer_id, status and amount. Customers maps three customer IDs to a segment. You can inspect the headers before importing:

order_id,customer_id,status,amount
1,101,paid,120
2,102,paid,80
3,101,refunded,50
4,103,paid,200
5,102,pending,40
6,101,paid,60

Filter rows before calculating revenue

Refunded and pending orders should not count here. Select the paid rows, then calculate their total:

SELECT COUNT(*) AS paid_orders, SUM(amount) AS revenue
FROM orders_csv
WHERE status = 'paid';
Expected result
paid_ordersrevenue
4460

Join a second CSV

Join on the customer ID and group by segment. This avoids manually copying the segment into every order row.

SELECT c.segment, COUNT(*) AS paid_orders, SUM(o.amount) AS revenue
FROM orders_csv AS o
JOIN customers_csv AS c USING (customer_id)
WHERE o.status = 'paid'
GROUP BY c.segment
ORDER BY revenue DESC;
Expected revenue by customer segment
segmentpaid_ordersrevenue
Business3380
Individual180

Check the join before using a real export

A duplicate customer ID can multiply order rows in a join. This check should return no rows for the sample:

SELECT customer_id, COUNT(*) AS copies
FROM customers_csv
GROUP BY customer_id
HAVING COUNT(*) > 1;

An inner join excludes orders without a matching customer. Use a left join if unmatched orders must remain, and inspect missing segments before drawing conclusions.

Keep the query and export the result

Save the SQL in a worksheet or notebook. Run one statement with Run query, or select Run all for the whole script. Export the result from the results area. The original CSV files are unchanged.

CSV details to watch

Automatic type detection depends on the file contents. Dates, decimal separators and mixed text/number columns may need explicit conversion. Quote a column name containing spaces with double quotes. Keep both files loaded while running the join; the beta permits three files of up to 100 MB each.

For parser options and SQL readers, consult DuckDB CSV documentation. This guide uses the views created by RawQL, so you do not need to enter a filesystem path in SQL.