ITeye博客

sql的AVG如何实现保留一位小数(数据库里为int型)?

ch_dj · 2015-03-12 10:01 · 数据库 · 数据库 · Markdown

select b.unitCode,b.unit,AVG(b.age*1.0) avgAge from (select ((2015-SUBSTRING(birthday,0,5))12+(3-SUBSTRING(birthday,5,2)))/12 as age ,a. from TRT_CADRES a) b where unit is not null group by b.unitCode,b.unit

AVG(b.age*1.0)

select case when avg(colname1.0)=cast(avg(colname1.0) as int) then avg(colname1.0) else cast(avg(colname1.0) as decimal(9,1)) end

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。