几条特殊的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分页,需 ...
随机推荐
- Internationalization
Internationalization If you are building a site for an international audience, you will likely want ...
- 数据库通用Jdbc操作
public class JdbcUtil { /** * 关闭一个数据库链接 * @param conn */ public static void closeConnection(Connecti ...
- ViewFlipper的简单使用实现图片轮播效果
/** * ViewFlipper: * 安卓系统自带的一个多页面管理控件,它可以实现子页面的自动切换 * 为ViewFlipper加入View: * (1)在layout布局文件静态导入子View ...
- How to center a div in bootstrap3
There are two approaches to centering a column <div> in Bootstrap 3: Approach 1 (offsets): The ...
- Javascript中new
// 加不加new结果都一样 var obj = new Function('var temp = 100;this.temp = 200;return temp + this.temp;'); al ...
- UVa 1645 Count(**)
题目大意:输入n,统计有多少个n个结点的有根树,使得每个深度中所有结点的子结点数相同.结果模1000000007. 思路:根据题意,每个结点的每个子树都是相同的.所以n结果为n-1的所有约数的结果加起 ...
- 程序员,一起玩转GitHub版本控制,超简单入门教程 干货2
本GitHub教程旨在能够帮助大家快速入门学习使用GitHub,进行版本控制.帮助大家摆脱命令行工具,简单快速的使用GitHub. 做全栈攻城狮-写代码也要读书,爱全栈,更爱生活. 更多原创教程请关注 ...
- Jquery 实现Xml文件内容处理
用JS对XMl文件处理实现和用JS处理一般的Dom元素一样; 加载一个Xml内容与新建一个Dom元素基本相同 如: 1.新建一个Dom元素的Jquey语法为:$("<p>hell ...
- 批量杀进程——xargs用途
ps -ef|grep ora|grep “LOCAL=YES”|awk ‘{print $2}’|xargs –I {} kill -9 {} ps -ef|grep ora|grep “LOCAL ...
- 实现ios屏幕的横竖屏自适应
整理总结中... 刷新 可以通过 -setNeedsUpdateConstraints -layoutIfNeeded 两个方法来刷新约束的改变,使UIView重新布局, 和CoreGraphic的- ...