Subject | [firebird-support] WITH RECURSIVE... SELECT MAX from result |
---|---|
Author | Codebue Fabio - P-Soft |
Post date | 2009-03-09T14:59:51Z |
I wanna explode my hierchical table with a WITH RECURSIVE statement.
And there are no problems...
WITH RECURSIVE
DiBa AS (
SELECT
P.CODICE_COMMESSA AS CODICE_COMMESSA,
P.ID AS ID, P.art_codice_padre AS ART_CODICE_PADRE,
P.SEQUENZA AS SEQUENZA, P.LIVELLO AS LIVELLO,
P.art_codice_figlio AS ART_CODICE_FIGLIO,
P.DESCRIZIONE AS DESCRIZIONE,
P.DATA_INIZIO AS DATA_INIZIO, P.DATA_FINE AS DATA_FINE
FROM dsb_tmp P
WHERE P.CODICE_COMMESSA = :CODICE_COMMESSA
UNION ALL
SELECT
D.CODICE_COMMESSA AS CODICE_COMMESSA,
D.ID AS ID, D.art_codice_padre AS ART_CODICE_PADRE,
D.SEQUENZA AS SEQUENZA, D.LIVELLO AS LIVELLO,
D.art_codice_figlio AS ART_CODICE_FIGLIO,
D.DESCRIZIONE AS DESCRIZIONE,
D.DATA_INIZIO AS DATA_INIZIO, D.DATA_FINE AS DATA_FINE
FROM dsb_tmp D
INNER JOIN DiBa P ON D.art_codice_padre = P.art_codice_figlio )
SELECT * FROM DiBa
When when I try to find a max from one of this field It loop infinitely...
Sigh
[.......]
SELECT Max(LIVELLO) AS MAXLIVELLO FROM DiBa
Codebue Fabio
And there are no problems...
WITH RECURSIVE
DiBa AS (
SELECT
P.CODICE_COMMESSA AS CODICE_COMMESSA,
P.ID AS ID, P.art_codice_padre AS ART_CODICE_PADRE,
P.SEQUENZA AS SEQUENZA, P.LIVELLO AS LIVELLO,
P.art_codice_figlio AS ART_CODICE_FIGLIO,
P.DESCRIZIONE AS DESCRIZIONE,
P.DATA_INIZIO AS DATA_INIZIO, P.DATA_FINE AS DATA_FINE
FROM dsb_tmp P
WHERE P.CODICE_COMMESSA = :CODICE_COMMESSA
UNION ALL
SELECT
D.CODICE_COMMESSA AS CODICE_COMMESSA,
D.ID AS ID, D.art_codice_padre AS ART_CODICE_PADRE,
D.SEQUENZA AS SEQUENZA, D.LIVELLO AS LIVELLO,
D.art_codice_figlio AS ART_CODICE_FIGLIO,
D.DESCRIZIONE AS DESCRIZIONE,
D.DATA_INIZIO AS DATA_INIZIO, D.DATA_FINE AS DATA_FINE
FROM dsb_tmp D
INNER JOIN DiBa P ON D.art_codice_padre = P.art_codice_figlio )
SELECT * FROM DiBa
When when I try to find a max from one of this field It loop infinitely...
Sigh
[.......]
SELECT Max(LIVELLO) AS MAXLIVELLO FROM DiBa
Codebue Fabio