Words
78
Reading
1 min
Listen
Play
1y
Looks like you are having fun!
Again, here are some tips to improve performance:
Encapsulating your main query in a sub-query (
WITH ExchangePayouts AS) can be detrimental because it forces the server to process ALL rows before applying the TOP restriction. This can make a huge difference when you process millions of rows.You can use
GETUTCDATE() - [days]instead of using DATEADD() if you are adding/substracting days. Again this makes your query more readable.
Here is how I would rewrite your query:
SELECT TOP 50
[from] AS [user],
[to] AS recipient,
SUM(amount) AS total_hive_withdrawn
FROM
TxTransfers
WHERE
amount_symbol = 'HIVE'
AND type = 'transfer'
AND timestamp >= GETUTCDATE() - 7 -- Filters last 7 days
GROUP BY
[from],
[to]
ORDER BY
total_hive_withdrawn DESC
RE: HiveSQL - Querying to find out HIVE Coming IN [Users] & Going OUT [Exchanges]