sql server 2008关联统计(sum、count、case、group by)
来源:互联网 发布:海康威视网络球机接线 编辑:程序博客网 时间:2024/05/17 07:24
--总表 统计select ProjectType ,CompletedTime,count(distinct ProjectId) as ProjectCount,--COUNT(distinct RelatedTabId) as WellCount,COUNT(distinct position) as PositionCount,COUNT(distinct ManageMan) as ManageManCount,COUNT(distinct ProjectType) as ProjectTypeCount,--根据ManageUnit 和 RelatedTabName统计个数sum(case when ManageUnit=1 and RelatedTabName='A' then 1 else 0 end) as MCCount, sum(case when ManageUnit=1 and RelatedTabName='B' then 1 else 0 end) as MCCount2, sum(case when ManageUnit=1 and RelatedTabName='C' then 1 else 0 end) as MCCount3, sum(case when ManageUnit=1 and RelatedTabName='D' then 1 else 0 end) as MCCount4, sum(case when ManageUnit=3 and RelatedTabName='A' then 1 else 0 end) as MDCount, sum(case when ManageUnit=3 and RelatedTabName='B' then 1 else 0 end) as MDCount2, sum(case when ManageUnit=3 and RelatedTabName='C' then 1 else 0 end) as MDCount3, sum(case when ManageUnit=3 and RelatedTabName='D' then 1 else 0 end) as MDCount4, sum(case when ManageUnit=3 and RelatedTabName='E' then 1 else 0 end) as MDCount5, --根据 RelatedTabName统计个数sum(case when RelatedTabName='A' then Area else 0 end) as MArea, sum(case when RelatedTabName='B' then Area else 0 end) as MArea2, sum(case when RelatedTabName='C' then Area else 0 end) as MArea3, sum(case when RelatedTabName='D' then Area else 0 end) as MArea4, --面积(亩)SUM(Area) as TotalArea from ( select a.ProjectId as ProjectId,a.Village as Village, a.TownShip as TownShip,a.CompletedTime as CompletedTime, a.ProjectType as ProjectType,a.ManageMan as ManageMan, a.IrrigateType as IrrigateType,a.ResourceType as ResourceType, a.Area as Area, convert(varchar(50),a.TownShip)+','+convert(varchar(50),a.Village) as position, a.ManageMode as ManageUnit,b.RelatedTabId as RelatedTabId, b.RelatedTabName as RelatedTabName from A_ProjectInfo a left join ( select RelatedTabId, ProjectId,RelatedTabName from A_ProjectInfo_Relate where 1=1 and RelatedTabId in (select MachineId from A_Well) ) b on a.ProjectId=b.ProjectId where 1=1 --查询条件 --and a.TownShip={0} --and a.Village={0} --and a.ProjectType='{0}' --and a.CompletedTime<='{0}' ) t group by t.CompletedTime,t.ProjectType order by t.CompletedTime,t.ProjectType
- sql server 2008关联统计(sum、count、case、group by)
- sql中group by ,order by,sum,count用法
- SQL group by & count
- Sql server Group by 统计数量 order by时间
- sql server 中的group by 和 having count
- count,group by,having(SQL)
- oracle sum case when group by,同时使用,实现分组统计
- 一个sql的四种写法:sum...case.when、sum if、select(select..)、group by
- MySQL中的 COUNT、SUM与 GROUP BY
- sql server 之group by的用法(关于统计)
- group by & count分组统计数量
- SQL编程实例:Access数据库,两张表的统计,count、sum聚合函数的使用,iif的使用,group by的使用
- 巧用case进行分类求和(case & group by & sum)
- SQL结果统计 GROUP BY
- SQL SERVER 2008 GROUP BY GROUPING SETS
- linq to sql (Group By/Having/Count/Sum/Min/Max/Avg操作符)
- sql查询 -count,group by,havi..
- SQL GROUP BY 无记录 COUNT
- 批量处理某类特征按钮touch事件
- Line宣布用户数达到3亿 四个月内新增1亿
- Postgresql 安装与配置 .
- 黑马程序员--Java基础加强(7)-----代理和AOP(面向方面编程)
- ExtJS设置Datepicker默认值
- sql server 2008关联统计(sum、count、case、group by)
- 各种正则表达式
- 选择 冒泡 插入 快排 堆排序 排序
- cocos2dx hellolua 例子
- 文件系统对象及装载
- ASSERT_VALID和ASSERT宏分析
- 网络套接字发送结构体及数据处理
- Android开源库集锦
- hdu 1811 拓扑排序+并查集