SELECT t3.COMPANYCODE AS COMPANYCODE,t3.SECUCODE AS SECUCODE,t3.TOTALSCORE_Z AS TOTALSCORE_Z,t1.lessCount AS LESSCOUNT,
t2.totalCount AS TOTALCOUNT, CAST((LESSCOUNT / TOTALCOUNT * 100) AS DECIMAL) AS SCOREORDER, t3.TRADINGDAY
FROM (
SELECT COUNT(COMPANYCODE) AS lessCount
FROM ANALYZE.IMATRIX_CUBE_SUBSCORE
WHERE TradingDay = (SELECT tradingday FROM IMATRIX.TRADINGDAY_VIEW ORDER BY TRADINGDAY DESC FETCH FIRST 1 ROWS ONLY)
AND TOTALSCORE_Z < (
SELECT TOTALSCORE_Z
FROM ANALYZE.IMATRIX_CUBE_SUBSCORE
WHERE TradingDay = (SELECT tradingday FROM IMATRIX.TRADINGDAY_VIEW ORDER BY TRADINGDAY DESC FETCH FIRST 1 ROWS ONLY)
AND COMPANYCODE = 74627
)
) t1,(
SELECT COUNT(COMPANYCODE) AS totalCount
FROM ANALYZE.IMATRIX_CUBE_SUBSCORE
WHERE TradingDay = (SELECT tradingday FROM IMATRIX.TRADINGDAY_VIEW ORDER BY TRADINGDAY DESC FETCH FIRST 1 ROWS ONLY)
) t2,(
SELECT TRADINGDAY,COMPANYCODE,SECUCODE,TOTALSCORE_Z
FROM ANALYZE.IMATRIX_CUBE_SUBSCORE
WHERE TradingDay = (SELECT tradingday FROM IMATRIX.TRADINGDAY_VIEW ORDER BY TRADINGDAY DESC FETCH FIRST 1 ROWS ONLY)
AND COMPANYCODE = 74627
) t3
查询结果
ROW_NUMBER()——生成行号
OVER()——窗口函数,类似于分组的功能
FIRST_VALUE()——取分组中的第一条记录,常用语窗口函数中
SELECT *
FROM (
SELECT secucode,secuabbr,tradingday,PREVCLOSEPRICE,CLOSEPRICE,
-- ROW_NUMBER()——生成行号
-- OVER()——窗口函数,根据股票代码分组并由交易日降序排序
ROW_NUMBER() OVER(PARTITION BY SECUCODE ORDER BY TRADINGDAY DESC) RN,
-- FIRST_VALUE()——取第一条记录的指定值
FIRST_VALUE(CLOSEPRICE) OVER(PARTITION BY SECUCODE ORDER BY TRADINGDAY) P_START
FROM imatrix.imatrix_cube_basic
WHERE (tradingday > to_date('2018-01-01', 'yyyy-mm-dd') and tradingday < to_date('2018-02-01', 'yyyy-mm-dd'))
AND secucode in ('300058', '002901')
) WHERE RN = 1
结果
listagg()——分组拼接对应属性名
SELECT
name,
chiname,
listagg('"' || name,'",') within GROUP (order by name) over()
FROM
imatrix.imatrix_factors
WHERE
chiname IS NOT NULL
AND
table_name = 'IMATRIX_CUBE_MAIN_INDEX'
结果
deepin安装Oracle 12c R2(详细)
oracle中to_char函数转换后多出空格的问题
navicat premium连接Oracle几个步骤
Navicat Premium已破解版x86+x64 v12.0.24免费绿色版
Navicat 12注册样例
Navicat Premium 12连接Oracle时提示oracle library is not loaded的问题解决
plsql developer 64位破解版下载(附注册码+安装教程) v11.0.4.1788
Ubuntu 16.04 安装 Oracle SQL Developer
dbeaver远程连接数据库Oracle
Oracle SQL Developer 连接 MySQL
sql 保留两位小数+四舍五入
Oracle SQL语句操作数字:取整、四舍五入及格式化
mysql中now()函数在oracle中怎么用
mysql查看数据库和表的占用空间大小
SQL INSERT INTO 语句
Oracle绝对值函数
mysql的between的边界问题
使用Ora2Pg工具把数据从Oracle导入到PostgreSQL
使用ora2pg完成从oracle到postgresql的迁移工作
Ora2Pg的安装和使用
使用Ora2Pg工具把数据从Oracle导入到PostgreSQL