select item_no,convert(varchar(7),make_date,120),sum(item_num) from( select * from tb a where not exists(select 1 from tb where comp_id=a.comp_id and item_no=a.item_no and convert(varchar(7),make_date,120)=convert(varchar(7),a.make_date,120) and make_date>a.make_date) )t group by item_no,convert(varchar(7),make_date,120)
select item_no,sum(item_num) from ( select * from zl_zz_account t where make_date in(select max(make_date) from zl_zz_account a where item_no=t.item_no and comp_id=t.comp_id group by item_no,comp_id order by accountid desc) ) a group by item_no 应该是这么写了 谢谢上面的朋友
select a.item-no,sum(item-num) 'item-num' from tab a inner join (select compid,item-no,max(Make_date) maxMake_date from tab where datepart(m,Make_date)=[指定的月] group by compid,item-no) b on a.compid=b.compid and a.item-no=b.item-no and a.Make_date=b.maxMake_date group by a.item-no
我要对itemno分组 然后呢 求得每种compid 最大日期 itemnum的和 条件是时间可以查询
放到gridview中 两个字段列 完毕
比如说34这这一类分组了 统计数就是 138
select * from tb a
where not exists(select 1 from tb where comp_id=a.comp_id and item_no=a.item_no and convert(varchar(7),make_date,120)=convert(varchar(7),a.make_date,120) and make_date>a.make_date)
)t group by item_no,convert(varchar(7),make_date,120)
select * from zl_zz_account t where
make_date in(select max(make_date) from zl_zz_account a where item_no=t.item_no and comp_id=t.comp_id group by item_no,comp_id order by accountid desc)
) a
group by item_no 应该是这么写了 谢谢上面的朋友
select a.item-no,sum(item-num) 'item-num'
from tab a
inner join
(select compid,item-no,max(Make_date) maxMake_date
from tab
where datepart(m,Make_date)=[指定的月]
group by compid,item-no) b
on a.compid=b.compid and a.item-no=b.item-no
and a.Make_date=b.maxMake_date
group by a.item-no