一个关于SQL视图的问题

来源:百度知道 编辑:UC知道 时间:2024/06/14 17:53:17
我要建立一个视图,该视图实现的功能是:按年月份统计数据,比如,用一条记录显示2009年3月份金额总数(3月份有多条记录),用一条记录显示2009年4月份金额总数(4月份有多条记录)...,每个月统计数据用一条记录显示,请问该怎么做?
谢谢 大家的回答,目前已经解决,正确的答案是:SELECT SUM(floSumPrice) AS SUM, CONVERT(varchar(7), datTime, 120) AS MONTH
FROM dbo.WipeDetail
GROUP BY CONVERT(varchar(7), datTime, 120)

select sum(amount),month,year from table group by month
若是没有month,year字段,则需要稍微处理下

以上答案参考

select count(金额) group by (月份)
其中月份的条件你要自己设置一下

金额总数不等于记录数,我认为你要的应该是记录数。

create view yourviewName
as
select convert(varchar(7),datefield,120) +'月' as '月份',count(1) as '记录数' from
yourtable group by convert(varchar(7),datefield,120) +'月'

金额总数不等于记录数,我认为你要的应该是记录数。

create view yourviewName
as
select convert(varchar(7),datefield,120) +'月' as '月份',count(1) as '记录数' from
yourtable group by convert(varchar(7),datefield,120) +'月'
select sum(amount),month,year from table group by month
若是没有month,year字段,则需要稍微处理下