SQL Server 统计报表(不断收藏中)
来源:互联网 发布:我欲封天灵宠进阶数据 编辑:程序博客网 时间:2024/06/16 03:49
create table #t (out_no varchar(10) primary key,date datetime,part varchar(30),qty numeric(12,4),price numeric(12,4))insert into #tselect 'A01','2009-1-11','B001',100,1.1 union allselect 'A02','2009-1-12','B002',200,1.3 union allselect 'A03','2009-2-22','B003',120,1.5 union allselect 'A04','2009-3-22','B004',155,1.2 union allselect 'A05','2009-4-20','B005',600,1.6 union allselect 'A06','2009-4-22','B006',750,1.6 ----select * from #tselect 月份='出货数量', [1月]=sum(case when month(date)=1 then qty else 0 end), [2月]=sum(case when month(date)=2 then qty else 0 end), [3月]=sum(case when month(date)=3 then qty else 0 end), [4月]=sum(case when month(date)=4 then qty else 0 end), [5月]=sum(case when month(date)=5 then qty else 0 end)from #tunion allselect 月份='出货金额', [1月]=sum(case when month(date)=1 then price*qty else 0 end), [2月]=sum(case when month(date)=2 then price*qty else 0 end), [3月]=sum(case when month(date)=3 then price*qty else 0 end), [4月]=sum(case when month(date)=4 then price*qty else 0 end), [5月]=sum(case when month(date)=5 then price*qty else 0 end)from #t/*月份 1月 2月 3月 4月 5月-------- --------------------------------------- --------------------------------------- --------------------------------------- ------------------------出货数量 300.0000 120.0000 155.0000 1350.0000 0.0000出货金额 370.0000 180.0000 186.0000 2160.0000 0.0000(2 行受影响)*/drop table #t
2、
假设我们有一字段名为name,其值是用逗号分隔的。
值为:'111,111xu2,1112'。
现在,我们需要编写语句搜索该name值 like '11'的。
按理说,这个name中没有11,我们要的结果就是返回空。
但是如果我们 select * from student where name like '%11%'的话,依然可以正常的查询出结果。
---
此时,我们应该采用如下的语句来实现:
select * from student where name like '%11%' --按照我的想法是不能查到的。但结果是查到了
--解决办法是:将sql字段名前后加上,号,并且比较值前后也加上。
--特别注意的是:字段名加逗号时,要用字符串连接的形式,不能直接 ',name,'
select * from student where ','+name+',' like '%,111,%'
--解决办法是:将sql字段名前后加上,号,并且比较值前后也加上。
--特别注意的是:字段名加逗号时,要用字符串连接的形式,不能直接 ',name,'
select * from student where ','+name+',' like '%,111,%'
- SQL Server 统计报表(不断收藏中)
- [SQL Server]统计SQL Server 报表的订阅情况
- 一些解决方案收藏(不断搜集补充中)
- Oracle 报表统计SQL
- 复杂SQL集合(不断收集中)
- SQL统计报表中1-12月的数据
- SQL SERVER 报表统计(根据时间)如当天、昨日、本周、上周、本月、上月、同期等时间过滤
- 本人收藏的Sql server经典t-sql语句(备忘录,持续更新中)
- SQL SERVER 交叉报表
- SQL Server报表服务
- sql server 文章收藏
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- [收藏]利用SQL Server Reporting Services 从应用程序生成用户友好的报表
- SQL语句做报表统计
- DownloadError: android.googlesource.com: <urlopen error [Errno 111] Connection refused>
- Dataguard 主备库切换(failover)
- 软件项目管理流程总结
- You cannot combine custom titles with other title feature
- Freenas8图文教程1--搭建ISCSI存储
- SQL Server 统计报表(不断收藏中)
- JS 弹出登陆框窗口,关闭窗口之后,使原来的窗口打开新的JSP
- Freenas8图文教程2--搭建NFS和CIFS
- 状态模式
- '/etc/init.d/rcS'启动打不开
- Web邮件发送客户端 [ html + php + python ]
- 在Windows应用程序中设计菜单栏、工具栏和状态栏
- C语言运算符级别分类
- 操作数据库之查、增、删、改、统计、排序、混合查询、指定条数、不重复记录