SELECT from_unixtime(uts,'%u') as week_number
, [COLOR=blue]from_unixtime(uts -
mod(from_unixtime(uts,'%w')+6,7)
*86400) as start_of_week [/color]
, count(*) as orders
from ordersTable
WHERE from_unixtime(uts,'%Y')=2006
GROUP
BY from_unixtime(uts,'%u')
, [COLOR=blue]from_unixtime(uts -
mod(from_unixtime(uts,'%w')+6,7)
*86400) [/color]