几条特殊的SQL语句
1, 有case情况。
select trunc(exf_payment_receipt.work_date),exf_payment_receipt.exchange_code,
exf_payment_receipt.bill_no,exf_payment_type.name, exf_payment_receipt.total_money,
case exf_payment_receipt.status when '0' then '正常' else '已撤销' end,
case exf_payment_receipt.flag when '0' then '未对账'
when '1' then '对账相符'
when '2' then '财政多出'
when '3' then '本行多出'
when '4' then '金额不符'
else '状态不符' end
from exf_payment_receipt, exf_payment, exf_payment_type
where exf_payment_receipt.exf_payment_id = exf_payment.id
and exf_payment_type.code = exf_payment.payment_type_code ;
2, 数据更新 从一个表更新一条记录到另一个表中。infodept表比org_info表多出 datekey列。
insert into infodept select '20130731',* from org_info;
3,按照理财产品 渠道 处理。
select L.deptid,L.cpdm,L.clrq,D.deptname,
sum(case when L.jyqd ='柜面渠道' then 1 else 0 end) as cnt1,
sum(case when L.jyqd ='柜面渠道' then L.amount else 0 end) as amt1,
sum(case when L.jyqd ='网银渠道' then 1 else 0 end) as cnt2,
sum(case when L.jyqd ='网银渠道' then L.amount else 0 end) as amt2
from lccpmx L,infodept D
where L.deptid=D.deptid and D.datekey=L.clrq
and (D.branch1='0000' or D.branch2='0000' or D.branch3='0000'or D.branch4='0000') and L.cpdm='1332'
group by L.deptid,L.cpdm,L.clrq,D.deptname
ORDER BY L.deptid ;
4,另一种方式的case
insert into paymentbusinessincome_q(datekey,year,quarter,deptid,zfjsamt,zjamt,yysramt)
select '2013-03-31' as datekey,'2013' as year,'1' as quarter,deptid,
sum(case when subjid in ('602101') and datekey='2013-03-31' then crcbal-decbal else 0 end) as zfjsamt,--支付结算业务收入
sum(case when subjid in ('6021') and datekey='2013-03-31' then crcbal-decbal else 0 end) as zjamt, --中间业务收入
sum(case when subjid in ('6051') and datekey='2013-03-31' then crcbal-decbal else 0 end)+ -- 1 其他业务收入
sum(case when subjid in ('6061') and datekey='2013-03-31' then crcbal-decbal else 0 end)+ ---2 汇兑收益
sum(case when subjid in ('6101') and datekey='2013-03-31' then crcbal-decbal else 0 end)+ -- 3 公允价值变动收益
sum(case when subjid in ('6111') and datekey='2013-03-31' then crcbal-decbal else 0 end)+ -- 4 投资收益
sum(case when subjid in ('6021') and datekey='2013-03-31' then crcbal-decbal else 0 end)- --B 手续费及佣金收入
sum(case when subjid in ('6421') and datekey='2013-03-31' then decbal-crcbal else 0 end)+ --5 =B-A B手续费及佣金净收入 A 手续费及佣金支出
sum(case when subjid in ('6011') and datekey='2013-03-31' then crcbal-decbal else 0 end)-
sum(case when subjid in ('6411') and datekey='2013-03-31' then decbal-crcbal else 0 end) as yysramt --6=D-C 利息净收入 D 利息收入 C 利息支出
from decrsubjtotal where datekey='2013-03-31'
and deptid in (select deptid from infodept where datekey='2013-03-31' and (branch1='0000' or branch2='0000' or branch3='0000' or branch4='0000'))
group by deptid;
几条特殊的SQL语句的更多相关文章
- 不同数据库,查询前n条数据的SQL语句
不同的数据库,支持的SQL语法略有不同,以下是不同数据库查询前n条数据的SQl语句 SQL Server(MSSQL) SELECT TOP n * FROM table_name ORACLE SE ...
- sql插入多条数据的sql语句
sql插入多条数据的sql语句 有三种方法:1.InSert Into <表名>(列名)Select <列名>From <源表名>如:INSERT INTO Ton ...
- Mybatis 删除多条数据XML SQL语句删除
Mybatis 删除多条数据XML SQL语句删除 1.删除多条数据SQL写法 <delete id="deleteParamsByIds"> delete from ...
- “取出数据表中第10条到第20条记录”的sql语句+selecttop用法
1.首先,select top用法: 参考问题 select top n * from和select * from的区别 select * from table -- 取所有数据,返回无序集合 sel ...
- “取出数据表中第10条到第20条记录”的sql语句+select top 使用方法
1.首先.select top使用方法: 參考问题 select top n * from和select * from的差别 select * from table -- 取全部数据.返回无序集合 ...
- 各数据库查询前N条记录的SQL语句
sql在不同数据库查询前几条数据 1. ORACLE SELECT * FROM TABLE_NAME WHERE ROWNUM <= N; HQL: from table_name t or ...
- 几条复杂的SQL语句
表结构:CREATE TABLE [dbo].[Exam]( [S_date] [datetime] NOT NULL, [Order_Id] [varchar](50) NOT NULL ...
- 如何随机从数据库表中抽一条数据的SQL语句
NewID() 方法返回一个 GUID,如:EE95A489-B721-4E8A-8171-3CA8CB6AD9E4 在 select 表的时候,再增加一列为 NewID() 就可以了. SQL 语句 ...
- mysql中删除重复记录,并保留重复数据中的一条数据的SQL语句
正好想写一条删除重复语句并保留一条数据的SQL,网上查了一部分资料写的很详细,但还是在这里写下自己的理解,以遍后续学习 .如下: 表字段和数据: SQL语句: [sql] view plain cop ...
- 一条分页的SQL语句
1.概述 在网页中如果显示的数据太多就会占据过多的页面,而且显示速度也会很慢.为了控制每次在页面上显示数据的数量,就可以利用分页来显示数据. 2.技术要点 在SQL Server中要实现SQL分页,需 ...
随机推荐
- CLI Console
CLI Console New to 3.0 is a command line utility aptly named Nova located in the root. It currently ...
- String使用equals方法和==分别比较的是什么?
equals方法和==的区别 首先大家知道,String既可以作为一个对象来使用,又可以作为一个基本类型来使用.这里指的作为一个基本类型来使用只是指使用方法上的,比如String s = &quo ...
- 如何取消tableView的footer的粘滞效果
footer默认的是固定在底部的 但有时我们需要和view一起滚动 主要是在scrollViewDidScroll这个代理方法中监听滚动的状况 设置如下 - (void)scrollViewDidS ...
- Android 自学之基本界面组件(上)
文本款(TextView)和编辑框(EditText)的功能和用法 TextView直接继承了View,他还是EditText.Button两个UI组件的父类,TextView的作用就是在界面上显示文 ...
- 2013 ACM/ICPC 长沙现场赛 A题 - Alice's Print Service (ZOJ 3726)
Alice's Print Service Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is providing print ser ...
- Centos 7中 vim 中文乱码
参考:http://www.myexception.cn/operating-system/1534005.html 一. sudo vim /etc/vimrc 在文件中加入如下几行: s ...
- 跨站脚本攻击(XSS)
跨站脚本攻击(XSS) XSS发生在目标网站中目标用户的浏览器层面上,当用户浏览器渲染整个HTML文档的过程中就出现了不被预期的脚本执行. 跨站脚本的重点不是在“跨站”上,而应该在“脚本上” 简单例子 ...
- 移动平台3G手机网站前端开发布局技巧
本文转载至:移动平台3G手机网站前端开发布局技巧汇总 - 前端开发-武方博 您或许正在或准备参与一个WepApp项目,您或许正在Google搜索mobile development相 关的文章,您或许 ...
- 牛客OJ——[编程题]A+B和C__如何输入多组测试数据(测试OK)
几个要注意的地方: (1)Java OJ,必须将类名写成Main (2)关于如何输入多组测试数据,用二维数组去存储是一个方法,直接在while里面做也可以 但是如果 (3)关于整形 ...
- ###学习《C++ Primer》- 3
点击查看Evernote原文. #@author: gr #@date: 2014-10-04 #@email: forgerui@gmail.com Part 3: STL泛型算法(第10章) 一. ...