SQL order groups in table without GROUP BY

Multi tool use
SQL order groups in table without GROUP BY
I have a quote_logs table where there are groups of logs(about 8 logs in each group). Every group has quote_log_group field which has the same value for the group(for example 1530599717507).
I need SQL statement to get all quote logs, sorted by the net_charge field in each group.
Rows in the table look like this:
Expected sample output:
*id* *net_charge* *quote_log_group*
5 - 110 - group1
7 - 120 - group1
2 - 130 - group1
4 - 140 - group1
3 - 150 - group1
11 - 110 - group2
15 - 120 - group2
12 - 130 - group2
13 - 140 - group2
14 - 150 - group2
Most people here want formatted text, not images.
– jarlh
Jul 3 at 7:26
You can ORDER BY multiple columns. For instance first on quote_log_group followed by net_charge : ORDER BY quote_log_group, net_charge See: dev.mysql.com/doc/refman/8.0/en/sorting-rows.html
– KIKO Software
Jul 3 at 7:28
1 Answer
1
You can order the query by quote_log_group
to get all the rows in the same group one of the other and then by net_charge
:
quote_log_group
net_charge
SELECT *
FROM quote_logs
ORDER BY quote_log_group, net_charge
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you post the expected output? also, post what you have tried.
– Jignesh Patel
Jul 3 at 7:26