如果我要统计其中的I_SUM字段: select i_sum from table1 group by year(date1) 就可以了吗?
select convert(char(4), date_col, 112), sum(...) from tab1 where convert(char(4), date_col, 112) = @year group by convert(char(4), date_col, 112) select convert(char(6), date_col, 112), sum(...) from tab1 where convert(char(6), date_col, 112) = @year group by convert(char(6), date_col, 112) select convert(char(8), date_col, 112), sum(...) from tab1 where convert(char(8), date_col, 112) = @year group by convert(char(8), date_col, 112)
不行啊,SELECT 后的字段名必须用SUM吗?
用group by 就必须用统计函数,如:sum(), count(), max(), min()等。
select i_sum
from table1
group by year(date1)
就可以了吗?
select convert(char(6), date_col, 112), sum(...) from tab1 where convert(char(6), date_col, 112) = @year group by convert(char(6), date_col, 112)
select convert(char(8), date_col, 112), sum(...) from tab1 where convert(char(8), date_col, 112) = @year group by convert(char(8), date_col, 112)