Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Sort in reports

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Sort in reports

Unread post by kknm »

Why sorting does not work in reports ?
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
]
ves.png
You do not have the required permissions to view the files attached to this post.
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Sort in reports

Unread post by Janusz »

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
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Sort in reports

Unread post by kev1n »

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
kknm
Posts: 366
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: Sort in reports

Unread post by kknm »

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
That doesn't work either.
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
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Sort in reports

Unread post by kev1n »

How does the sorting happen? I don't see a ORDER BY.
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Sort in reports

Unread post by Janusz »

ORDER BY does not work together with UNION in phpmyadmin, too.
https://stackoverflow.com/questions/353 ... l/32848661

the above maybe can help

or the simpler solution: make second view which will make just the sorting of the first view :-) maybe crazy but works
If you like nuBuilder, please leave a review on SourceForge
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Sort in reports

Unread post by admin »

Guys,
kknm wrote:Why sorting does not work in reports ?
When a Report is run it takes the data and orders it by the Group Properties in the Report.
gb2.png

This Report is ordered by ves_num which is sorted as a String not a Number.
ves.png
Steven
You do not have the required permissions to view the files attached to this post.
Post Reply