物流公司统计按物资类别采购的前二十家sql
2、集团主要的供应商(按物资分类列举前10或20家名单),年采购金额、占比,结算方式,付款周期;(夏)
年份要求是2013年
arap_djfb中的单据日期不是常规的日期类型

需要做这样的转换才可以
select to_char(to_date(billdate,'yyyy,mm,dd'),'yyyy' )from arap_djfb
按照材料类别的分类需要截取字段的后两位
select areaclcode,substr(bd_areacl.areaclcode,-2), substr(bd_areacl.areaclcode,length(bd_areacl.areaclcode)-1,2) from bd_areacl
感谢影哥的-2,我搞复杂了

sql如下
select --arap_djzb.djbh 单据编号,
--arap_djfb.billdate as 单据日期,
--bd_corp.unitname as 付款单位,
-- arap_djfb.zy as 付款摘要,
sum(arap_djfb.bbye) as allmoney ,
--arap_djfb.fkyhmc as 付款银行名称,
--(select bankacc from bd_accbank where pk_accbank = arap_djfb.fkyhzh) 付款银行账号,
--bd_cubasdoc.custcode as 收款单位编码,
--bd_cubasdoc.custname as 收款单位名称,
bd_accbank.unitname 收款单位名称,
--bd_accbank.bankname as 收款银行名称,
--bd_accbank.bankacc as 收款银行账号,
bd_areacl.areaclcode,
bd_areacl.areaclname
-- arap_djfb.payflag
from bd_cubasdoc, arap_djfb, bd_cumandoc, arap_djzb, bd_corp, bd_accbank,bd_areacl
where arap_djfb.ksbm_cl = bd_cumandoc.pk_cumandoc
and bd_cumandoc.pk_cubasdoc = bd_cubasdoc.pk_cubasdoc
and arap_djfb.vouchid = arap_djzb.vouchid
and bd_corp.pk_corp = arap_djzb.dwbm
and bd_accbank.pk_accbank = arap_djfb.skyhzh
and bd_areacl.pk_areacl=bd_cubasdoc.pk_areacl
and arap_djfb.payflag in ('', '')
and arap_djfb.dr = ''
--and (select bankacc from bd_accbank where pk_accbank = arap_djfb.fkyhzh) ='32001735038059899999'
--and bd_corp.unitcode='010201'
and substr(arap_djfb.billdate,1,4)=''
and bd_areacl.areaclcode<>''
and length(bd_accbank.unitname)>3
and bd_accbank.unitname not like '江苏省建工%'
--and bd_areacl.areaclname like '%沧州%'
-- and bd_cubasdoc.custcode = '17051211693'
group by bd_accbank.unitname, bd_areacl.areaclcode, bd_areacl.areaclname order by substr(bd_areacl.areaclcode,-2), allmoney desc
昨天晚上想到oracle应该可以分组取前20,于是百度,果然找到了itpub
http://www.itpub.net/thread-1290416-1-1.html
row_number()over(partition by substr(areaclcode,-2) order by allmoney desc) c1 这里c1不可以直接放在where条件,必须再嵌套一次
dense_rank()over也行
select * from (
select allmoney,unitname,areaclcode,areaclname,
row_number()over(partition by substr(areaclcode,-2) order by allmoney desc) c1 from
(select --arap_djzb.djbh 单据编号,
--arap_djfb.billdate as 单据日期,
--bd_corp.unitname as 付款单位,
-- arap_djfb.zy as 付款摘要,
sum(arap_djfb.bbye) as allmoney ,
--arap_djfb.fkyhmc as 付款银行名称,
--(select bankacc from bd_accbank where pk_accbank = arap_djfb.fkyhzh) 付款银行账号,
--bd_cubasdoc.custcode as 收款单位编码,
--bd_cubasdoc.custname as 收款单位名称,
bd_accbank.unitname ,
--bd_accbank.bankname as 收款银行名称,
--bd_accbank.bankacc as 收款银行账号,
bd_areacl.areaclcode,
bd_areacl.areaclname
-- arap_djfb.payflag
from bd_cubasdoc, arap_djfb, bd_cumandoc, arap_djzb, bd_corp, bd_accbank,bd_areacl
where arap_djfb.ksbm_cl = bd_cumandoc.pk_cumandoc
and bd_cumandoc.pk_cubasdoc = bd_cubasdoc.pk_cubasdoc
and arap_djfb.vouchid = arap_djzb.vouchid
and bd_corp.pk_corp = arap_djzb.dwbm
and bd_accbank.pk_accbank = arap_djfb.skyhzh
and bd_areacl.pk_areacl=bd_cubasdoc.pk_areacl
and arap_djfb.payflag in ('', '')
and arap_djfb.dr = ''
--and (select bankacc from bd_accbank where pk_accbank = arap_djfb.fkyhzh) ='32001735038059899999'
--and bd_corp.unitcode='010201'
and substr(arap_djfb.billdate,1,4)=''
and bd_areacl.areaclcode<>''
and length(bd_accbank.unitname)>3
and bd_accbank.unitname not like '江苏省建工%'
--and bd_areacl.areaclname like '%沧州%'
-- and bd_cubasdoc.custcode = '17051211693'
group by bd_accbank.unitname, bd_areacl.areaclcode, bd_areacl.areaclname order by substr(bd_areacl.areaclcode,-2), allmoney desc))
where c1<=20

物流公司统计按物资类别采购的前二十家sql的更多相关文章
- destoon信息或者公司归属多个类别的解决方式
有时候,一条信息属对应于多个类别,在destoon原生系统里是没有这个解决方案 在公司行业类别选择的地方实现了这个功能,但是选择体验不太好,不符合我当前的需求,目前我写了如下解决方案 系统代码如下: ...
- win8扁平风格的物流公司网站后台管理模板——后台
链接:http://pan.baidu.com/s/1o79Zp2M 密码:tqrz
- K2 BPM_采购端到端解决方案,激活合规采购新动能_十年专注业务流程管理系统
「方案背景」企业管理标准化演进之路 企业的成长离不开标准化,企业的可持续发展更离不开标准化.随着市场竞争的日趋激烈,标准化已经成为企业参与市场竞争的战略性手段,也成为企业可持续发展的重要手段.聚焦到采 ...
- 数据可视化之powerBI技巧(二十)采悟:创建度量值,轻松进行分组统计
上一篇文章中的分组,都是通过新建列的方式实现的,直观上比较容易理解.不过这样都修改了原始数据的结构,如果我们不在源表上进行修改,直接通过度量值的方式来进行分组,是否可以实现呢? 答案当然是肯定的. 采 ...
- Oracle学习笔记四 SQL命令(二):SQL操作语言类别
SQL分为下列语言类别 1.数据定义语言(DDL) Create.Alter.Drop 2.数据操纵语言(DML) Insert.Select.Delete.Update 3.事务控制语言(TCL) ...
- 统计某一字段等于不同值的个数的sql语句(分享)
本文介绍下,用一条sql语句统计某一字段等于不同值的个数,方法很独特,有需要的朋友参考下. 表t,数据: id type001 1001 0002 1001 ...
- Java进阶(二十六)公司项目开发知识点回顾
公司项目开发知识点回顾 前言 "拿来主义"在某些时候并不是最佳选择,尤其是当自己遇到问题的时候,毫无头绪. 在一次实验过程中,需要实现数据库的CRUD操作.由于之前项目开发过程中, ...
- 统计一个数据库中,无记录的表的sql语句
SQL Server数据库中统计无记录数的表 大家使用的时候,将sql脚本中的红色[TestDB] 换成你的目标数据库名称. /************************************ ...
- 二十、dbms_stats(用于搜集,查看,修改数据库对象的优化统计信息)
1.概述 作用:用于搜集,查看,修改数据库对象的优化统计信息. 2.包的组成 1).get_column_stats作用:用于取得列的统计信息语法:dbms_stats.get_column_stat ...
随机推荐
- PDF 补丁丁 0.4.3.1342 测试版发布:修复崩溃问题
PDF 补丁丁 0.4.3.1342 测试版发布了. 此测试版修复了之前测试版在合并文件.书签编辑器.文档结构探查器中出现的崩溃问题. 推荐下载了0.4.3测试版的网友尽快更新.
- 1362. Classmates 2
http://acm.timus.ru/problem.aspx?space=1&num=1362 水题,树形DP 代码: #include<iostream> #include& ...
- 请把不听话的【return】关进【class】这个笼子
请把不听话的[return]关进[class]这个笼子 问:powershell 最垃圾的语句是什么?答:(函数中的)return #例子1:函数中的return有时会返回所有内容,而不是你想要的内容 ...
- 简单工厂模式(Simple Factory)
从设计模式的类型上来说,简单工厂模式是属于创建型模式,又叫做静态工厂方法(Static Factory Method)模式,但不属于23种GOF设计模式之一.简单工厂模式是由一个工厂对象决定创建出哪一 ...
- 一个null引发的错误
写程序时,发生一个unrecognized selector的错误,很显然,这是一个经典错误,运行时找不到可调用的方法. 系统提示的reason是 -[NSNull length] 错误 经过查找,原 ...
- 用CSS定义每段首行缩进2个字符 转
应该遵循w3c所制定的html/xhtml标准来使用tag和编写网页.如果你对此不太了解,可以到w3c的网站www.w3.org去找相关资料,或者买一本xhtml的书(注意不要买过时的html的书,尽 ...
- Jquery EasyUI Tree .net实例
图片: 针对tree: 数据库: CREATE TABLE [dbo].[SystemModel]( [Id] [,) NOT NULL, [Name] [nvarchar]() NULL, [Fat ...
- Day9 summary
昨天又翻出收藏夹里一个叫“谷子粒”的bloghttp://1.guzili.sinaapp.com/?p=128#more-128,链接是博主整理的机器学习方面的热点微博,相当的干货.要说我是从知乎对 ...
- javascript笔记6-DOM
DOM(文档对象模型)是针对HTML和XML文档的一个API.DOM描绘了一个层次化的节点树,允许程序员添加.修改页面的一部分. 节点层次:DOM可以将任何HTML或XML文档描绘成一个由多层次节点构 ...
- get到的新技能
1.重拾选择器 (一)类选择器与id选择器的区别 W3C标准这样规定的,在同一个页面内,不允许有相同名字的id对象出现,但是允许相同名字的class. 这样,一般网站分为头,体,脚部分,因为考虑到它们 ...