两张表合并统计
2016-01-13 10:25
267 查看
两张表:一张存储设备编号、状态;另一张存储设备编号、所属工地。要求:统计出每个工地设备在线和离线的数目
USE [GPSClient] GO /****** 对象: StoredProcedure [dbo].[StatisticsContruction] 脚本日期: 01/13/2016 10:13:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <主页使用,获取全部工地,及在线离线设备数目> -- ============================================= ALTER PROCEDURE [dbo].[StatisticsContruction] -- Add the parameters for the stored procedure here @CustomID varchar(10), @recCount int=0 output AS BEGIN ------------------------------------------------------------------------- with temp1 as ( select ##realtimedata.clientserial ,##realtimedata.clientStutas,construction from ##realtimedata full join server_synchro_info on ##realtimedata.clientserial = server_synchro_info.clientserial where ##realtimedata.defaultTag2='200023' group by construction,construction,##realtimedata.clientStutas, ##realtimedata.clientserial ) select isNULL(construction,'未指定工地砂浆罐') as 'construction' , count( case clientStutas when 1 then '在线' end )as 'OnLineCount' , count( case clientStutas when 0 then '离线' end )as 'OffLineCount' from temp1 group by construction set @Reccount = @@ROWCOUNT END 测试方法: exec statisticsContruction '200023'
相关文章推荐
- Android 的 dex2jar 和 jd-gui 反编译 apk 源代码
- 跟我一起写Makefile 读书笔记
- 手机APP模式 之 Hybrid App(混合模式移动应用)
- Node.js基础学习
- svn命令在linux下的使用
- 支付宝支付时不验证签名的危害
- UIScrollView循环滚动
- 心路(一)
- node.js初识
- ASP.NET数据绑定之Repeater控件
- 特殊排列的算法
- Swift中文教程(一)基础数据类型
- CodeForces 606A-A. Magic Spheres【模拟】
- java发邮件(1)
- TCP连接的建立(二)
- JAVA线程同步辅助类Exchanger-交换
- 对一个多态例题学习的一些思考
- cocos2d-x 卓上改变工程图标的步骤
- 用消息队列和消息应用状态表来消除分布式事务
- 免费午餐已结束:并发成为软件的基本转向