SQL snippets in Trevor

If you're used to writing SQL, it'll take you just a few minutes to get used to Trevor.io's interface. 

  • In Trevor.io, you build queries as a series of atomic steps.
  • Each extra step you add modifies the results in some way. 
  • There are very few limits to number of steps you can add and the complexity you can therefore layer into your query.  

Here are some examples of how to basic SQL operations in Trevor.io.

1️⃣ Sort

SELECT *
FROM Extras
ORDER BY price DESC

how_to_sort_in_Trevor.io.gif

2️⃣ Filter

SELECT *
FROM Customers
WHERE nationality = 'United States'
OR nationality = 'Germany'

how_to_filter_data_in_Trevor.io.gif

3️⃣ Aggregate

SELECT country, COUNT(*)
FROM Customers
GROUP BY country

how_to_aggregate_data_in_Trevor.io.gif

4️⃣ Group by week

SELECT
    DATE_TRUNC('week', pick_up),
    COUNT(*)
FROM Reservations
GROUP BY 1

how_to_group_by_week_in_trevor.io.gif

5️⃣ Specify time range

SELECT *
FROM customers
WHERE signed_up_at <
    ('now'::TIMESTAMP
        - '6 months'::INTERVAL)

time_limit_in_Trevor.io.gif

6️⃣ Join with a group by

SELECT p.name, 
coalesce(sum(p.price_usd), 0) as "sum_price_usd"
FROM orders
LEFT JOIN products ON o.product_id = p.id
GROUP BY 1
ORDER BY "sum_price_usd" DESC

join_and_group_by_in_trevor.io.gif

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.