Sqlite Sorting Sum Column Values
SELECT SUM(bytes),stamp_updated from acct where stamp_updated BETWEEN datetime('now', 'localtime','-7 hours') AND datetime('now', 'localtime') GROUP BY ip_src ORDER BY bytes DE
Solution 1:
You're ordering with your bytes column before they are aggregated. Try this:
SELECTSUM(bytes) AS total_bytes, stamp_updated
FROM acct
WHERE stamp_updated BETWEEN datetime('now', 'localtime','-7 hours') AND datetime('now', 'localtime')
GROUPBY ip_src
ORDERBY total_bytes DESC limit 10;
Solution 2:
You're aggregating on the field you're trying to sort by. Those single pieces of data don't exist anymore on their own but rather as the total for each element you're grouping by.
Maybe you're trying to order by SUM(bytes)?
Apart from that, consider grouping by all non aggregated fields in the select statement... you're missing stamp_updated in the group by.
Post a Comment for "Sqlite Sorting Sum Column Values"