数据库字段分别是id,count,year,month,date,其中id和year,month,date联合做主键,统计每条广告的点击量。
现在要求统计一段时间内的一条广告的点击量,
在数据库中的sql语句是select id,sum(count) 
from lava_HitCount 
where 
year >= 2010 and 2010 >= year 
and month >= 12 and 12 >= month 
and date >= 8 and 10 >= date 
group by id如何将sum(count)值显示到DataGrid中?

解决方案 »

  1.   

    不明真相。你是要显示明细和统计都有吗?用报表(Report)不是很好啊。
      

  2.   

    不显示明细,只显示统计。
    比如id=1的广告今天被点击一次,昨天也被点击一次,如果统计这两天的点击量,则直接显示1条id=1的数据,现在我想知道怎么能把这个点击量2显示在DataGrid中?
      

  3.   

    不显示明细就是普通的绑定了,是你的SQL语句问题select id,year,month,date,sum(count) 
    from lava_HitCount 
    where 
    year >= 2010 and 2010 >= year 
    and month >= 12 and 12 >= month 
    and date >= 8 and 10 >= date 
    group by id,year,month,date这样就行了,你可以在DataGrid里他年月日等信息也显示出来。
      

  4.   


    select id,sum(count) as count
    from lava_HitCount 
    where 
    year >= 2010 and 2010 >= year 
    and month >= 12 and 12 >= month 
    and date >= 8 and 10 >= date 
    group by id
    --把count当做字段,像平常那样绑定就可以!--
      

  5.   


    ds.Tables[0].Columns.Add("count");
    row["count"]=sel_count();