sql使用

select s_info_windcode from asharettmandmrq where 
report_period between  20170506 and 20180525 order by report_period asc
image.png

提取最新的流通股数

先选出wind代码、流通股、变动日期 按照wind代码分类,将变动日期排序,从高到低,并编号
再选出wind代码、流通股股数,从n=1里面提取,也就是最新的那期

select s_info_windcode, float_shr * 10000 as float_shr from 
(select s_info_windcode,float_shr,change_dt, row_number() over(partition by s_info_windcode order by change_dt desc) as n from asharecapitalization) where n = 1
image.png

image.png

解释部分

row_number() over()
将分数从大到小排列,并将其排名

select [name],gender,fenshu, row_number() over(order by fenshu desc) as num from dbo.PeopleInfo

将男女分别算,还是将分数排名并排名次

select [name],gender,fenshu, row_number() over(partition by Gender order by fenshu desc) as num from dbo.PeopleInfo

matlab中插入临时表

fastinsert(conn,'temp_windcode',{'stockcode'},StockCode);

创建临时表,复制temp_windcode的结构,不复制数据

create table temp_windcode_xia as select * from temp_windcode where 1=0;

你可能感兴趣的:(sql使用)