[Solved] WHILE ROLLUP in base parser, or alternative

Creating tables and queries
Locked
Nikos
Posts: 175
Joined: Mon Dec 17, 2007 11:50 am

[Solved] WHILE ROLLUP in base parser, or alternative

Post by Nikos »

I have the following query, that works when send directly to MariaDB, but not when send via the parser.

Code: Select all

SELECT `ANK`.`company`, `ANK`.`journal`,`ANK`.`pb`, `ANK`.`db`, `DEUTERO`.`dbdesc`,
 SUM( CASE WHEN `ANK`.`year` = 2024 THEN `ANK`.`dc` END ) AS `T`,  
 SUM( CASE WHEN `ANK`.`year` = 2024 - 1 THEN `ANK`.`dc` END ) AS `T_prev`, 
 SUM( CASE WHEN `ANK`.`year` = 2024 THEN `ANK`.`dc` END ) - SUM( CASE WHEN `ANK`.`year` = 2024 - 1 THEN `ANK`.`dc` END ) AS `Diff`,
 ( SUM( CASE WHEN `ANK`.`year` = 2024 THEN `ANK`.`dc` END ) / NULLIF ( SUM( CASE WHEN `ANK`.`year` = 2024 - 1 THEN `ANK`.`dc` END ), 0 ) - 1 ) AS `Percent` 
 FROM `ANK` LEFT JOIN `DEUTERO` ON `ANK`.`db` = `DEUTERO`.`db` WHERE `ANK`.`year` >= 2024 - 1 AND `company` = 'VD' AND `ANK`.`omada` = '6' AND `ANK`.`month` <= 12 AND `ANK`.`journal` = 'ΓΗ'
GROUP BY `ANK`.`pb`, `ANK`.`db` WITH ROLLUP

The problem is the usage of "WITH ROLLUP"

I would like the years, company and journal to be parameters ( =:par ), which means I would like to use the parser.
However, the ROLLUP function does not seem to be understood by the parser.
What are my alternatives?
Last edited by MrProgrammer on Thu Aug 21, 2025 3:56 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] Q: What are my alternatives?; A: Two provided
LibreOffice 25.2 on Kubuntu 25.4 (flatpak) + LibreOffice 25.2 on Ubuntu 25.4 (flatpak)
Jan_J
Posts: 189
Joined: Wed Apr 29, 2009 1:42 pm
Location: Poland

Re: WHILE ROLLUP In the base parser or an alternative

Post by Jan_J »

The SQL parser in Base seems somewhat aggresive, especially when you use non-native SQL dialect.
You can establish server-side named view

Code: Select all

CREATE VIEW view_name AS query_text;
and refer to it in a query

Code: Select all

SELECT * FROM view_name;
Last edited by Jan_J on Thu Aug 14, 2025 2:07 pm, edited 1 time in total.
JJ ∙ https://forum.openoffice.org/pl/
LO (25.2|24.8) ∙ Python (3.12|3.10) ∙ Unicode 16 ∙ LᴬTEX 2ε ∙ XML ∙ Unix tools ∙ Linux (Rocky|CentOS)
UnklDonald418
Volunteer
Posts: 1573
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: WHILE ROLLUP In the base parser or an alternative

Post by UnklDonald418 »

A Filter table would be another option especially with multiple parameters
There is a lengthy discussion of the concept at
Filter/Search with Forms (leveraging SubForms)
but skip down near the bottom and download the example database named
LIKE_user_input_filter.odb
It has good descriptions on how it works.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
Sliderule
Volunteer
Posts: 1291
Joined: Thu Nov 29, 2007 9:46 am

Re: WHILE ROLLUP In the base parser or an alternative

Post by Sliderule »

Your original post is below:

Code: Select all

SELECT 
   `ANK`.`company`, `ANK`.`journal`,`ANK`.`pb`, `ANK`.`db`, `DEUTERO`.`dbdesc`,
    SUM( CASE WHEN `ANK`.`year` = 2024 THEN `ANK`.`dc` END ) AS `T`,  
    SUM( CASE WHEN `ANK`.`year` = 2024 - 1 THEN `ANK`.`dc` END ) AS `T_prev`, 
    SUM( CASE WHEN `ANK`.`year` = 2024 THEN `ANK`.`dc` END ) - SUM( CASE WHEN `ANK`.`year` = 2024 - 1 THEN `ANK`.`dc` END ) AS `Diff`,
    ( SUM( CASE WHEN `ANK`.`year` = 2024 THEN `ANK`.`dc` END ) / NULLIF ( SUM( CASE WHEN `ANK`.`year` = 2024 - 1 THEN `ANK`.`dc` END ), 0 ) - 1 ) AS `Percent` 
FROM `ANK` LEFT JOIN `DEUTERO` ON `ANK`.`db` = `DEUTERO`.`db` 
    WHERE `ANK`.`year` >= 2024 - 1 
        AND `company` = 'VD' 
        AND `ANK`.`omada` = '6' 
        AND `ANK`.`month` <= 12 
        AND `ANK`.`journal` = 'ΓΗ'
GROUP BY `ANK`.`pb`, `ANK`.`db` WITH ROLLUP
Run the SQL Query below ( with LibreOffice Base Parser ), and, confirms it performs what you need. What I did was to add two lines, first line and last line, to hide the SELECT statement from LibreOffice Base parser.

Code: Select all

-- LINE Below Added By Sliderule for testing with LibrOffice Base Parser
SELECT `A`.* FROM (  
      SELECT 
         `ANK`.`company`, `ANK`.`journal`,`ANK`.`pb`, `ANK`.`db`, `DEUTERO`.`dbdesc`,
          SUM( CASE WHEN `ANK`.`year` = 2024 THEN `ANK`.`dc` END ) AS `T`,  
          SUM( CASE WHEN `ANK`.`year` = 2024 - 1 THEN `ANK`.`dc` END ) AS `T_prev`, 
          SUM( CASE WHEN `ANK`.`year` = 2024 THEN `ANK`.`dc` END ) - SUM( CASE WHEN `ANK`.`year` = 2024 - 1 THEN `ANK`.`dc` END ) AS `Diff`,
          ( SUM( CASE WHEN `ANK`.`year` = 2024 THEN `ANK`.`dc` END ) / NULLIF ( SUM( CASE WHEN `ANK`.`year` = 2024 - 1 THEN `ANK`.`dc` END ), 0 ) - 1 ) AS `Percent` 
      FROM `ANK` LEFT JOIN `DEUTERO` ON `ANK`.`db` = `DEUTERO`.`db` 
      WHERE `ANK`.`year` >= 2024 - 1 
          AND `company` = 'VD' 
          AND `ANK`.`omada` = '6' 
          AND `ANK`.`month` <= 12 
          AND `ANK`.`journal` = 'ΓΗ'
      GROUP BY `ANK`.`pb`, `ANK`.`db` WITH ROLLUP
-- LINE Below Added By Sliderule for testing with LibreOffice Base Parser
) as `A`
Sliderule

Thanks to add [Solved] in your 1st post Subject (edit button top right) if this issue has been resolved.
Locked