0
Good evening. This sql was running exactly as I wanted, but yesterday started to get out of the field order g gallery.. It had an output (example) like this: GALLERY 10: 26 / GALLERY 11: 23 / GALLERY 12: 21 and so on. Now it’s totally out of order, I don’t understand. Someone sees the error?
WITH quantidade as(
Select g.galeria, g.tipo, g.finalidade, count(p.galeria) as total
from presos p
full join galerias g
on p.galeria = g.galeria
group by g.galeria,g.tipo,g.finalidade
order by g.galeria
)
Select string_agg(cast(g.tipo as text) || ' ' || cast(g.galeria as text) || ': ' || q.total, ' / ')
from galerias g full join quantidade q on (q.galeria = g.galeria and q.tipo = g.tipo and q.finalidade = g.finalidade)
WHERE g.galeria <= 50
See if you include the
order by g.galeria
afterWHERE g.galeria <= 50
resolves. It would:WHERE g.galeria <= 50 order by g.galeria
. Maybe you deleted it by mistake or the sort could be configured in some Delphi component that you have replaced and not configured again. Take a test and give feedback.– Clarck Maciel
Save Clarck...had already tried this......
– Jones713
The problem may be due to use in
WITH quantidade as
... are usingorder by g.galeria
and in chargeSelect string_agg(cast(g.tipo as text)
is started withg.tipo
. See the simulation performed on sqlfiddle. To improve understanding, I suggest you simulate your situation in another environment similar to what I did in the sqlfiddle.– Clarck Maciel