]SELECT ves_num,
SUM(ves_kol) AS sum_kol,
TRUNCATE(SUM(ves_tn)/1000,2) AS sum_tn
FROM vesyauto
JOIN tabel ON vesyauto.ves_tab = tabel.tabel_id
WHERE MONTH(tabel.tab_data)='06' AND YEAR(tabel.tab_data)='2020'
GROUP BY ves_num ASC
UNION ALL
SELECT 'ИТОГО:', SUM(ves_kol),TRUNCATE(SUM(ves_tn)/1000,2)
FROM vesyauto
ORDER BY ves_num ASC
Welcome to the nuBuilder Forums!
Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
Sort in reports
-
- Posts: 377
- Joined: Sat Apr 11, 2020 12:03 am
- Has thanked: 3 times
- Been thanked: 4 times
- Contact:
Sort in reports
Why sorting does not work in reports ?
You do not have the required permissions to view the files attached to this post.
-
- nuBuilder Team
- Posts: 508
- Joined: Fri Dec 28, 2018 1:41 pm
- Location: Krakow, Poland
- Has thanked: 11 times
- Been thanked: 18 times
Re: Sort in reports
In such cases I am defining view directly on DB level with phpmyadmin and after I refer to the view as to any other table. For me it's very conveniant and easy to debug.
If you like nuBuilder, please leave a review on SourceForge
-
- nuBuilder Team
- Posts: 4562
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 76 times
- Been thanked: 528 times
- Contact:
Re: Sort in reports
Code: Select all
The ORDER BY is just applied to the 2nd select. Try this:
Select *
from
(
SELECT ves_num,
SUM(ves_kol) AS sum_kol,
TRUNCATE(SUM(ves_tn)/1000,2) AS sum_tn
FROM vesyauto
JOIN tabel ON vesyauto.ves_tab = tabel.tabel_id
WHERE MONTH(tabel.tab_data)='06' AND YEAR(tabel.tab_data)='2020'
GROUP BY ves_num ASC
UNION ALL
SELECT 'ИТОГО:', SUM(ves_kol),TRUNCATE(SUM(ves_tn)/1000,2)
FROM vesyauto
) results
ORDER BY ves_num ASC
-
- Posts: 377
- Joined: Sat Apr 11, 2020 12:03 am
- Has thanked: 3 times
- Been thanked: 4 times
- Contact:
Re: Sort in reports
That doesn't work either.kev1n wrote:Code: Select all
The ORDER BY is just applied to the 2nd select. Try this: Select * from ( SELECT ves_num, SUM(ves_kol) AS sum_kol, TRUNCATE(SUM(ves_tn)/1000,2) AS sum_tn FROM vesyauto JOIN tabel ON vesyauto.ves_tab = tabel.tabel_id WHERE MONTH(tabel.tab_data)='06' AND YEAR(tabel.tab_data)='2020' GROUP BY ves_num ASC UNION ALL SELECT 'ИТОГО:', SUM(ves_kol),TRUNCATE(SUM(ves_tn)/1000,2) FROM vesyauto ) results ORDER BY ves_num ASC
ORDER BY does not work together with UNION in phpmyadmin, too.
This is how it works.
Code: Select all
SELECT ves_num,
SUM(ves_kol) AS sum_kol,
TRUNCATE(SUM(ves_tn)/1000,2) AS sum_tn
FROM vesyauto
JOIN tabel ON vesyauto.ves_tab = tabel.tabel_id
WHERE MONTH(tabel.tab_data)='06' AND YEAR(tabel.tab_data)='2020'
GROUP BY ves_num ASC
UNION ALL
SELECT 'ИТОГО:', SUM(ves_kol),TRUNCATE(SUM(ves_tn)/1000,2)
FROM vesyauto
-
- nuBuilder Team
- Posts: 4562
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 76 times
- Been thanked: 528 times
- Contact:
-
- nuBuilder Team
- Posts: 508
- Joined: Fri Dec 28, 2018 1:41 pm
- Location: Krakow, Poland
- Has thanked: 11 times
- Been thanked: 18 times
Re: Sort in reports
https://stackoverflow.com/questions/353 ... l/32848661ORDER BY does not work together with UNION in phpmyadmin, too.
the above maybe can help
or the simpler solution: make second view which will make just the sorting of the first view

If you like nuBuilder, please leave a review on SourceForge
Re: Sort in reports
Guys,
This Report is ordered by ves_num which is sorted as a String not a Number.
Steven
When a Report is run it takes the data and orders it by the Group Properties in the Report.kknm wrote:Why sorting does not work in reports ?
This Report is ordered by ves_num which is sorted as a String not a Number.
Steven
You do not have the required permissions to view the files attached to this post.