select row_number() over(partition by w.productCode order by w.CreatedDate desc) as row_number,w.wholeprice,w.productcode,w.CreatedDate
into #bb
from Input_Product_WholePrice_Final wselect A.index_id,A.productcode,bb.wholeprice
from #bb bb
right outer join
(
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;HDR=1;IMEX=1; Database=D:\北京价格.xlsx','SELECT *FROM [Sheet1$]')
)A on bb.productCode=A.productCode
where bb.row_number=1 order by A.index_idexcel表的格式是
index_id productcode
1 534534
2
3 654645
结构选出来的结果index_id=2的数据没选出来一开始用的不是临时表,用的是
with bb as
(
select row_number() over(partition by w.productCode order by w.CreatedDate desc) as row_number,w.wholeprice,w.productcode,w.CreatedDate
from Input_Product_WholePrice_Final w
)
选出的结果跟临时表是一样的,index_id=2的数据自动就筛掉了!我想保留index_id=2的数据~~~
想请教大家为甚么呢????
into #bb
from Input_Product_WholePrice_Final wselect A.index_id,A.productcode,bb.wholeprice
from #bb bb
right outer join
(
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;HDR=1;IMEX=1; Database=D:\北京价格.xlsx','SELECT *FROM [Sheet1$]')
)A on bb.productCode=A.productCode
where bb.row_number=1 order by A.index_idexcel表的格式是
index_id productcode
1 534534
2
3 654645
结构选出来的结果index_id=2的数据没选出来一开始用的不是临时表,用的是
with bb as
(
select row_number() over(partition by w.productCode order by w.CreatedDate desc) as row_number,w.wholeprice,w.productcode,w.CreatedDate
from Input_Product_WholePrice_Final w
)
选出的结果跟临时表是一样的,index_id=2的数据自动就筛掉了!我想保留index_id=2的数据~~~
想请教大家为甚么呢????
解决方案 »
- 怎么设置让SQLSERVER2008查询显示结果显示整个字段的值?
- 今天无意看到两个sql的表,是啥区别呢?
- 速度和索引问题,八百万的表十个字段,常用判断字段为5个,如何建立索引会更快些
- SQL2008创建的数据库,Delphi程序却访问不到
- 如何让页面总是显示在Iframe框架之中???
- 请教一个关于数据库还原的问题。(真的很急!先说谢谢!)
- 未能在索引页 (1:721) 中找到 RID '16009c41fe685dd1ef1707000100050000' 的索引条目(索引 ID 0,数据库 'sdo')
- 问一个求和的sql 语句,简单点的
- 不要秒(2003-03-06 09:14:08.000)
- 用2000系统下的SQL访问2003系统下的SQL数据库,如何实现!!急急急!
- 一条sql语句中的order by没有起作用
- 关于农历转公历基础资料表的问题
所以 join 没有找到拼配项。
index_id product wholeprice
2 null null
这种结果而且,right join 实现的不就是这种结果么如果#bb不是临时表 我用正常的表试了 ,就能得出2 null null
这样的结果
如果没有,就不会返回。
(
select row_number() over(partition by w.productCode order by w.CreatedDate desc) as row_number,w.wholeprice,w.productcode,w.CreatedDate
from Input_Product_WholePrice_Final w
)这个得到的数量和 select * from Input_Product_WholePrice_Final 是一样的,不会过滤值2、请确认SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;HDR=1;IMEX=1; Database=D:\北京价格.xlsx','SELECT *FROM [Sheet1$]') 这一部分的值 建议把这个 insert到一个临时表里面,然后看一下数据是两天还是三条。
right join 是返回你a 表(也就是execl)的所有值的,所以index_id =2 在正常情况下 肯定是会出现的