SQL
select
if (month(now()) = month(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 7 * id day), dayofmonth(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 7 * id day), '')
as Mon,
if (month(now()) = month(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 1 - 7 * id day), dayofmonth(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 1 - 7 * id day), '')
as Tue,
if (month(now()) = month(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 2 - 7 * id day), dayofmonth(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 2 - 7 * id day), '')
as Wed,
if (month(now()) = month(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 3 - 7 * id day), dayofmonth(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 3 - 7 * id day), '')
as Thu,
if (month(now()) = month(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 4 - 7 * id day), dayofmonth(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 4 - 7 * id day), '')
as Fri,
if (month(now()) = month(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 5 - 7 * id day), dayofmonth(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 5 - 7 * id day), '')
as Sat,
if (month(now()) = month(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 6 - 7 * id day), dayofmonth(concat(year(now()), '-', month(now()), '-01 00:00:00') - INTERVAL weekday(concat(year(now()), '-', month(now()), '-01 00:00:00')) - 6 - 7 * id day), '')
as Sun from tbl;
В tbl:
0
1
2
3
4
5