You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT "Pedido".,
ultimo_estado.ultimo_estado,
dinosaurio.,
"Persona"."id" AS "Persona.id",
"Persona"."nombre" AS "Persona.nombre",
"Persona"."apellido" AS "Persona.apellido"
FROM
(SELECT "Pedido"."id",
"Pedido"."motivo",
"Pedido"."PersonaId"
FROM "Pedidos" AS "Pedido") AS "Pedido"
LEFT OUTER JOIN "Personas" AS "Persona" ON "Pedido"."PersonaId" = "Persona"."id"
AND ("Persona"."deletedAt" IS NULL)
LEFT JOIN (
SELECT CASE
WHEN GREATEST(CANCELADOS."createdAt",
CONFIRMADOS."createdAt",
DEMORADOS."createdAt",
ENTREGADOS."createdAt",
FABRICANDOS."createdAt",
FACTURADOS."createdAt",
FINALIZADOS."createdAt",
PRESUPUESTADOS."createdAt") = CANCELADOS."createdAt" THEN 'Cancelado'
WHEN GREATEST(CANCELADOS."createdAt",
CONFIRMADOS."createdAt",
DEMORADOS."createdAt",
ENTREGADOS."createdAt",
FABRICANDOS."createdAt",
FACTURADOS."createdAt",
FINALIZADOS."createdAt",
PRESUPUESTADOS."createdAt") = CONFIRMADOS."createdAt" THEN 'Confirmado'
WHEN GREATEST(CANCELADOS."createdAt",
CONFIRMADOS."createdAt",
DEMORADOS."createdAt",
ENTREGADOS."createdAt",
FABRICANDOS."createdAt",
FACTURADOS."createdAt",
FINALIZADOS."createdAt",
PRESUPUESTADOS."createdAt") = DEMORADOS."createdAt" THEN 'Demorado'
WHEN GREATEST(CANCELADOS."createdAt",
CONFIRMADOS."createdAt",
DEMORADOS."createdAt",
ENTREGADOS."createdAt",
FABRICANDOS."createdAt",
FACTURADOS."createdAt",
FINALIZADOS."createdAt",
PRESUPUESTADOS."createdAt") = ENTREGADOS."createdAt" THEN 'Entregado'
WHEN GREATEST(CANCELADOS."createdAt",
CONFIRMADOS."createdAt",
DEMORADOS."createdAt",
ENTREGADOS."createdAt",
FABRICANDOS."createdAt",
FACTURADOS."createdAt",
FINALIZADOS."createdAt",
PRESUPUESTADOS."createdAt") = FABRICANDOS."createdAt" THEN 'Fabricando'
WHEN GREATEST(CANCELADOS."createdAt",
CONFIRMADOS."createdAt",
DEMORADOS."createdAt",
ENTREGADOS."createdAt",
FABRICANDOS."createdAt",
FACTURADOS."createdAt",
FINALIZADOS."createdAt",
PRESUPUESTADOS."createdAt") = FACTURADOS."createdAt" THEN 'Facturado'
WHEN GREATEST(CANCELADOS."createdAt",
CONFIRMADOS."createdAt",
DEMORADOS."createdAt",
ENTREGADOS."createdAt",
FABRICANDOS."createdAt",
FACTURADOS."createdAt",
FINALIZADOS."createdAt",
PRESUPUESTADOS."createdAt") = FINALIZADOS."createdAt" THEN 'Finalizado'
WHEN GREATEST(CANCELADOS."createdAt",
CONFIRMADOS."createdAt",
DEMORADOS."createdAt",
ENTREGADOS."createdAt",
FABRICANDOS."createdAt",
FACTURADOS."createdAt",
FINALIZADOS."createdAt",
PRESUPUESTADOS."createdAt") = PRESUPUESTADOS."createdAt" THEN 'Presupuestado'
END ultimo_estado, p.id as pedido_id
FROM "Pedidos" as p
LEFT JOIN "Cancelados" AS CANCELADOS ON CANCELADOS."PedidoId" = "p"."id"
LEFT JOIN "Confirmados" AS CONFIRMADOS ON CONFIRMADOS."PedidoId" = "p"."id"
LEFT JOIN "Demorados" AS DEMORADOS ON DEMORADOS."PedidoId" = "p"."id"
LEFT JOIN "Entregados" AS ENTREGADOS ON ENTREGADOS."PedidoId" = "p"."id"
LEFT JOIN "Fabricandos" AS FABRICANDOS ON FABRICANDOS."PedidoId" = "p"."id"
LEFT JOIN "Facturados" AS FACTURADOS ON FACTURADOS."PedidoId" = "p"."id"
LEFT JOIN "Finalizados" AS FINALIZADOS ON FINALIZADOS."PedidoId" = "p"."id"
LEFT JOIN "Presupuestados" AS PRESUPUESTADOS ON PRESUPUESTADOS."PedidoId" = "p"."id"
) as ultimo_estado on ultimo_estado.pedido_id = "Pedido"."id"
LEFT JOIN (
SELECT pedido."id" as pedido_id,
"Detalles->Hueso->Dinosaurio"."nombre" AS "Dinosaurio.nombre"
FROM "Pedidos" as pedido
LEFT JOIN (
SELECT *, ROW_NUMBER() OVER (PARTITION BY "PedidoId" ORDER BY (SELECT NULL)) AS RowNum FROM "Detalles"
) as detalle ON pedido."id" = detalle."PedidoId" and RowNum = 1
AND (detalle."deletedAt" IS NULL)
LEFT OUTER JOIN "Huesos" AS "Detalles->Hueso" ON detalle."HuesoId" = "Detalles->Hueso"."id"
AND ("Detalles->Hueso"."deletedAt" IS NULL)
LEFT OUTER JOIN "Dinosaurios" AS "Detalles->Hueso->Dinosaurio" ON "Detalles->Hueso"."DinosaurioId" = "Detalles->Hueso->Dinosaurio"."id"
AND ("Detalles->Hueso->Dinosaurio"."deletedAt" IS NULL) WHERE (pedido."deletedAt" IS NULL)
) as dinosaurio on dinosaurio.pedido_id = "Pedido"."id"
The text was updated successfully, but these errors were encountered:
SELECT "Pedido".,
ultimo_estado.ultimo_estado,
dinosaurio.,
"Persona"."id" AS "Persona.id",
"Persona"."nombre" AS "Persona.nombre",
"Persona"."apellido" AS "Persona.apellido"
FROM
(SELECT "Pedido"."id",
"Pedido"."motivo",
"Pedido"."PersonaId"
FROM "Pedidos" AS "Pedido") AS "Pedido"
LEFT OUTER JOIN "Personas" AS "Persona" ON "Pedido"."PersonaId" = "Persona"."id"
AND ("Persona"."deletedAt" IS NULL)
LEFT JOIN (
SELECT CASE
WHEN GREATEST(CANCELADOS."createdAt",
CONFIRMADOS."createdAt",
DEMORADOS."createdAt",
ENTREGADOS."createdAt",
FABRICANDOS."createdAt",
FACTURADOS."createdAt",
FINALIZADOS."createdAt",
PRESUPUESTADOS."createdAt") = CANCELADOS."createdAt" THEN 'Cancelado'
END ultimo_estado, p.id as pedido_id
FROM "Pedidos" as p
LEFT JOIN "Cancelados" AS CANCELADOS ON CANCELADOS."PedidoId" = "p"."id"
LEFT JOIN "Confirmados" AS CONFIRMADOS ON CONFIRMADOS."PedidoId" = "p"."id"
LEFT JOIN "Demorados" AS DEMORADOS ON DEMORADOS."PedidoId" = "p"."id"
LEFT JOIN "Entregados" AS ENTREGADOS ON ENTREGADOS."PedidoId" = "p"."id"
LEFT JOIN "Fabricandos" AS FABRICANDOS ON FABRICANDOS."PedidoId" = "p"."id"
LEFT JOIN "Facturados" AS FACTURADOS ON FACTURADOS."PedidoId" = "p"."id"
LEFT JOIN "Finalizados" AS FINALIZADOS ON FINALIZADOS."PedidoId" = "p"."id"
LEFT JOIN "Presupuestados" AS PRESUPUESTADOS ON PRESUPUESTADOS."PedidoId" = "p"."id"
) as ultimo_estado on ultimo_estado.pedido_id = "Pedido"."id"
LEFT JOIN (
SELECT pedido."id" as pedido_id,
"Detalles->Hueso->Dinosaurio"."nombre" AS "Dinosaurio.nombre"
FROM "Pedidos" as pedido
LEFT JOIN (
SELECT *, ROW_NUMBER() OVER (PARTITION BY "PedidoId" ORDER BY (SELECT NULL)) AS RowNum FROM "Detalles"
) as detalle ON pedido."id" = detalle."PedidoId" and RowNum = 1
AND (detalle."deletedAt" IS NULL)
LEFT OUTER JOIN "Huesos" AS "Detalles->Hueso" ON detalle."HuesoId" = "Detalles->Hueso"."id"
AND ("Detalles->Hueso"."deletedAt" IS NULL)
LEFT OUTER JOIN "Dinosaurios" AS "Detalles->Hueso->Dinosaurio" ON "Detalles->Hueso"."DinosaurioId" = "Detalles->Hueso->Dinosaurio"."id"
AND ("Detalles->Hueso->Dinosaurio"."deletedAt" IS NULL) WHERE (pedido."deletedAt" IS NULL)
) as dinosaurio on dinosaurio.pedido_id = "Pedido"."id"
The text was updated successfully, but these errors were encountered: