Welcome to Knowage Q&A, where you can ask questions and receive answers from other members of the community.
0 votes
1 view

Hi!

When I tried to execute the following a query the application showed the following error:

Query:

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '01'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '02'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '03'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '04'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '05'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '06'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '07'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '08'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '09'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '10'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '11'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

union all

(SELECT

    anio,mes,servicio,sum(total_cobrado)  

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '01'

group by anio,mes,servicio

order by sum(total_cobrado) desc

limit 5 )

Error:

log:

[ajp-bio-8009-exec-26] 04 Oct 2018 12:15:57,163 DEBUG it.eng.spagobi.tools.datasource.dao.DataSourceDAOHibImpl.loadDataSourceByLabel:164 - OUT
[ajp-bio-8009-exec-26] 04 Oct 2018 12:15:57,163 DEBUG it.eng.spagobi.commons.SingletonConfigCache.get:59 - GET :DATA_SET_SQL_VALIDATION=true
[ajp-bio-8009-exec-26] 04 Oct 2018 12:15:57,163 ERROR it.eng.spagobi.tools.dataset.service.ManageDataSetsForREST.getDataSet:697 - SQL is NOT a SELECT statement, or cont
ains keywords like INSERT, UPDATE, DELETE.
[ajp-bio-8009-exec-26] 04 Oct 2018 12:15:57,163 ERROR it.eng.spagobi.rest.interceptors.RestExceptionMapper.toResponse:59 - Catched service error:
it.eng.spagobi.utilities.exceptions.SpagoBIServiceException: Provided SQL is NOT a SELECT statement
        at it.eng.spagobi.tools.dataset.service.ManageDataSetsForREST.getDataSet(ManageDataSetsForREST.java:698)
        at it.eng.spagobi.tools.dataset.service.ManageDataSetsForREST.getDataSet(ManageDataSetsForREST.java:1596)
        at it.eng.spagobi.tools.dataset.service.ManageDataSetsForREST.getDataSetResultsAsJSON(ManageDataSetsForREST.java:1500)
        at it.eng.spagobi.tools.dataset.service.ManageDataSetsForREST.datatsetTest(ManageDataSetsForREST.java:1479)

The query is ok, I tested it on my environment and also it was validated on the web.

I appreciate your help.

BR,

Environment Knowage 6.2 - Linux - Chrome
in Data Set by (390 points)

1 Answer

+1 vote
Hi Guido,

the problem is caused by the round brackets! Erase them, they are are useless in your SQL statement.

Try this one:

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '01'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '02'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '03'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '04'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '05'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '06'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '07'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '08'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '09'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '10'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '11'

group by anio,mes,servicio

limit 5

union all

SELECT

    anio,mes,servicio,sum(total_cobrado)  total_cobrado

FROM c_intentos_cobro

where anio = (select max(anio) from c_intentos_cobro)

and  mes = '12'

group by anio,mes,servicio

limit 5

order by total_cobrado desc

Regards,

Nunzia
by (3.1k points)
...