Autor Zpráva
Lolita
Profil
Zdare,

mam tenhle select

SELECT
public.employe_worktime.employe_worktime_id AS employe_worktime_id,
public.employe_worktime.starttime AS start_time,
public.employes.employe_id AS employe_id,
public.employes.employe_name AS employe_name,
public.reservations.service_id AS service_id,
public.reservations.reservation_id AS reservation_id,
public.services.service_name AS service_name,
public.services.service_desc AS service_desc,
public.services.service_length AS service_length,
public.reservation_data.reservation_note AS reservation_note,
public.reservation_data.reservation_admin_note AS reservation_admin_note,
public.reservation_data.reservation_name AS reservation_name,
public.reservation_data.reservation_cellphone AS reservation_cellphone,
public.reservation_data.reservation_email AS reservation_email
,min(public.employe_worktime.starttime) as zacatek
,max(public.employe_worktime.starttime) as konec
FROM
public.employes
INNER JOIN public.employe_worktime ON (public.employes.employe_id = public.employe_worktime.employe_id)
LEFT OUTER JOIN public.reservations ON (public.employe_worktime.employe_worktime_id = public.reservations.employe_worktime_id)
LEFT OUTER JOIN public.services ON (public.reservations.service_id = public.services.service_id)
LEFT OUTER JOIN public.reservation_data ON (public.reservations.reservation_id = public.reservation_data.reservation_id)
WHERE date_part('day', public.employe_worktime.starttime) = ".$selected_day."
AND date_part('month', public.employe_worktime.starttime) = ".$selected_month."
AND date_part('year', public.employe_worktime.starttime) = ".$selected_year."
GROUP BY employe_worktime.starttime
,public.employe_worktime.employe_worktime_id
,employes.employe_id
,employes.employe_name
,reservations.service_id
,reservations.reservation_id
,services.service_name
,services.service_desc
,services.service_length
,reservation_data.reservation_note
,reservation_data.reservation_admin_note
,reservation_data.reservation_name
,reservation_data.reservation_cellphone
,reservation_data.reservation_email
ORDER BY employe_worktime.starttime,
employes.employe_id


no chtel bych byt v zacatek a konec nejmensi hodnoty pro public.employe_worktime.starttime a misto toho tam mam hodnoty public.employe_worktime.starttime pro ten kterej radek ):

Nevite co s tim?
Mastodont
Profil
Víme, začít znova a ujasnit si, jak se konstruují agregační dotazy. Zvláště to GROUP BY je fakt mohutný.
Mastodont
Profil
Zkus například
SELECT public.employes.employe_id, min(public.employe_worktime.starttime) as zacatek

GROUP BY public.employes.employe_id

a popřemýšlej, co ti to vrací za hodnoty.
Lolita
Profil
no group by sem tam nahazel takovej gigantickej, pacto mi to furt hazelo chyby, ze to a to musi byt v group by ... podivam se teda na to.
Mastodont
Profil
pacto mi to furt hazelo chyby, ze to a to musi byt v group by

Ano, pokud dáš sloupec do výstupu, tak musí být v GROUP BY nebo součástí agregační funkce. Základní chybou je právě tolik sloupců ve výstupu.
Lolita
Profil
Proste tohle vsechno v jednom selectu nevypisu, ze? :)

Teda leda ze bych udelal v tom selectu docasnou tabulku se selctem min a max a tu pak joinul :
Kajman_
Profil *
Lolita

Kdyz dáte v group by i employe_worktime.starttime, tak max a min nemá moc smysl. Když to vynecháte najde maximum a minimum pro sloupečky, které se ve všech položkách group by shodují navzájem.

Osobně jsem ale nepochopil, co vlastně očekáváte.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: