SQLinfo.ru - Все о MySQL

Форум пользователей MySQL

Задавайте вопросы, мы ответим

Вы не зашли.

#1 02.06.2022 11:11:12

shiyri
Участник
Зарегистрирован: 02.06.2022
Сообщений: 2

не работает сортировка в селекте внутри джойна

Помогите пожалуйста, у запроса:


select au.id as id, au.name_model, au.gos_numer, th.teh,  
os.sago,  sk.skzi,  rem.data_remonta1, st.id as tyagach, st2.id as pricep
from name_auto as au
left join svyazka_table as st on st.id_auto =  au.id
left join svyazka_table as st2 on st2.id_pricep =  au.id
left join (SELECT DATE_FORMAT(teh, '%d.%m.%Y') as teh, teh.id, id_auto from teh where udalen is null and teh > now() - INTERVAL 1 day Order by teh.id desc) th on th.id_auto = au.id
left join (SELECT DATE_FORMAT(sago, '%d.%m.%Y') as sago, os.id_auto from os_sk as os where udalen is null and os.sago > now() - INTERVAL 1 day) os on os.id_auto = au.id
left join (SELECT DATE_FORMAT(skzi, '%d.%m.%Y') as skzi, id_auto from skzi where udalen is null and skzi > now() - INTERVAL 1 day) sk on sk.id_auto = au.id
left join (SELECT DATE_FORMAT(remont.data_remonta1, '%d.%m.%Y') as data_remonta1, remont.id, remont.id_auto from remont ORDER BY remont.id DESC ) rem on rem.id_auto = au.id
where au.udal is null group by au.gos_numer ORDER BY au.id desc
 


в этой строке DESC не работает
left join (SELECT DATE_FORMAT(remont.data_remonta1, '%d.%m.%Y') as data_remonta1, remont.id, remont.id_auto from remont ORDER BY remont.id DESC ) rem on rem.id_auto = au.id

Неактивен

 

#2 02.06.2022 11:17:34

shiyri
Участник
Зарегистрирован: 02.06.2022
Сообщений: 2

Re: не работает сортировка в селекте внутри джойна

Разобрался...


select au.id as id, au.name_model, au.gos_numer, th.teh,  
os.sago,  sk.skzi,   DATE_FORMAT(max(rem.data_remonta1)) as data_remonta1, st.id as tyagach, st2.id as pricep
from name_auto as au
left join svyazka_table as st on st.id_auto =  au.id
left join svyazka_table as st2 on st2.id_pricep =  au.id
left join (SELECT DATE_FORMAT(teh, '%d.%m.%Y') as teh, teh.id, id_auto from teh where udalen is null and teh > now() - INTERVAL 1 day Order by teh.id desc) th on th.id_auto = au.id
left join (SELECT DATE_FORMAT(sago, '%d.%m.%Y') as sago, os.id_auto from os_sk as os where udalen is null and os.sago > now() - INTERVAL 1 day) os on os.id_auto = au.id
left join (SELECT DATE_FORMAT(skzi, '%d.%m.%Y') as skzi, id_auto from skzi where udalen is null and skzi > now() - INTERVAL 1 day) sk on sk.id_auto = au.id
left join remont as rem on rem.id_auto = au.id
where au.udal is null group by au.gos_numer ORDER BY au.id desc
 

Неактивен

 

Board footer

Работает на PunBB
© Copyright 2002–2008 Rickard Andersson