我写的查询结构如下, select convert(char(4),datepart(yy,date))+'/'+convert(char(2),datepart(mm,date)) as [年/月], sum(case valid when 'T' then money else 0 end) as 有效消费统计, sum(case valid when 'F' then money else 0 end) as 无效消费统计, sum(case valid when 'T' then 1 else 0 end) as 有效消费笔数, sum(case valid when 'F' then 1 else 0 end) as 无效消费笔数 from newsale group by date 但确显示出
select convert(char(4),datepart(yy,date))+'/'+convert(char(2),datepart(mm,date)) as [年/月], sum(case valid when 'T' then money else 0 end) as 有效消费统计, sum(case valid when 'F' then money else 0 end) as 无效消费统计, sum(case valid when 'T' then 1 else 0 end) as 有效消费笔数, sum(case valid when 'F' then 1 else 0 end) as 无效消费笔数 from newsale group by convert(char(4),datepart(yy,date))+'/'+convert(char(2),datepart(mm,date)) as [年/月]
selectconvert(char(7),getdate(),111) as[年/月],
sum(case valid when'T'thenmoneyelse0end) as 有效消费统计,
sum(case valid when'F'thenmoneyelse0end) as 无效消费统计,
sum(case valid when'T'then1else0end) as 有效消费笔数,
sum(case valid when'F'then1else0end) as 无效消费笔数
from newsale
groupbyconvert(char(7),getdate(),111)
--tryselectconvert(varchar(7),date,111)as[年/月],,sum(case valid when'T'thenmoneyelse0end) as 有效消费统计,
sum(case valid when'F'thenmoneyelse0end) as 无效消费统计,
sum(case valid when'T'then1else0end) as 有效消费笔数,
sum(case valid when'F'then1else0end) as 无效消费笔数
from newsale
groupbyconvert(varchar(7),date,111)
selectconvert(char(7),date,111) as[年/月],
sum(case valid when'T'thenmoneyelse0end) as 有效消费统计,
sum(case valid when'F'thenmoneyelse0end) as 无效消费统计,
sum(case valid when'T'then1else0end) as 有效消费笔数,
sum(case valid when'F'then1else0end) as 无效消费笔数
from newsale
groupbyconvert(char(7),date,111)
select convert(char(4),datepart(yy,date))+'/'+convert(char(2),datepart(mm,date)) as [年/月], sum(case valid when 'T' then money else 0 end) as 有效消费统计, sum(case valid when 'F' then money else 0 end) as 无效消费统计, sum(case valid when 'T' then 1 else 0 end) as 有效消费笔数, sum(case valid when 'F' then 1 else 0 end) as 无效消费笔数 from newsale group by convert(char(4),datepart(yy,date))+'/'+convert(char(2),datepart(mm,date))