Rails.cache.fetch("products", :expires_in => 10.minutes) do
....
end
select item,
SUM(IF(price_id = 'price1', price, 0)) as price1,
SUM(IF(price_id = 'price2', price, 0)) as price2
FROM pivot_sample GROUP BY item;
SET @rank=0;
SET @current_field=0;
select a.field_a, a.field_b,
@rank:=if(@current_field = a.field_a,@rank+1,0) as rank,
@current_field:=a.field_a as current
FROM (select field_a, field_b from test2 where field_a IN (1,2)
ORDER BY field_a, field_b DESC ) as a having rank < 3;
SELECT c.name, b.name, count(*) from unslugi as a
left join info as b on a.job_id=b.id
left join info as c on a.worker_id=c.id
WHERE a.usluga_okazana=1
GROUP BY a.job_id, a.worker_id;