例子:
SELECT
str_to_date(concat(year(a.tb_time),
date_format(a.tb_time,
'%m'),
'01'),
'%Y%m%d') tb_time,
cast(a.category_id as char) category_id,
a.category_name,
sum(a.tendered_sum)/sum(a.winbid) tendered_sum,
sum(a.winbid_sum)/sum(a.winbid) winbid_avg
from
( SELECT
a.tb_time,
a.category_id,
a.category_name,
a.tendered_sum,
a.winbid_sum,
case
when a.winbid_is = 'X'
and a.callbid_result = '授标结束' then '1'
else '0'
end winbid
from
v_bid_information a ) a
GROUP BY
year(a.tb_time),
month(a.tb_time),
a.category_id,
a.category_name