select if(CONCAT(year(ph.created), '_', week(ph.created)) = dt.cr, -1,
if(CONCAT(year(ph.created), '_', week(ph.created)) = dt.nx, -2, (year(ph.created) * 100) + week(ph.created))) t
from test ph
inner join (select CONCAT(year(now()), '_', week(now())) cr,
CONCAT(year(now()), '_', week(now()) + 1) nx from dual) dt on 1=1
order by t
WHERE (bl.`status` IN(1,2)) AND (bl.`user_id` IN (select id from <Table>))
Тип столбца TIMESTAMP обеспечивает тип представления данных, который можно использовать для автоматической записи текущих даты и времени при выполнении операций INSERT или UPDATE. При наличии нескольких столбцов типа TIMESTAMP только первый из них обновляется автоматически.
select selected_date, (select count(1) from tasks where selected_date between date_start and date_end) cnt from
(select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
where selected_date between (select min(date_start) from tasks) and (select max(date_end) from tasks)
select * from salon sl, admin ad
where (if(sl.model1 in (ad.model1, ad.model2, ad.model3, ad.model4, ad.model5), 1, 0) +
if(sl.model2 in (ad.model1, ad.model2, ad.model3, ad.model4, ad.model5), 1, 0) +
...
if(sl.model5 in (ad.model1, ad.model2, ad.model3, ad.model4, ad.model5), 1, 0)) >= 3