日期:2014-05-17  浏览次数:20433 次

行列转换后分页出错,求帮组,急急急!!!
这是我行列转换的的sql

select c.* from (
select legal_entity_id,process_date,record_id,amount from engine_fp where process_date='2013-06-25'
) s pivot (max(amount) for record_id in([23],[24],[25],[26],[27],[28],[29],[30],[31],[33],[34],[38])) 
c order by legal_entity_id


因为项目里面用的是hibernate 下面是它自己封装的分页sql,执行出错

WITH query AS (
SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ 
FROM ( 
select TOP(40) c.* as page0_ from (
select legal_entity_id,process_date,record_id,amount from engine_fp where process_date='2013-06-25'
) s pivot (max(amount) for record_id in([23],[24],[25],[26],[27],[28],[29],[30],[31],[33],[34],[38])) 
c order by legal_entity_id 
) inner_query 

) SELECT page0_ FROM query WHERE __hibernate_row_nr__ >= 20 AND __hibernate_row_nr__ < 40

原因是 select TOP(40) c.* as page0_ from 这里用as就出错
如果修改我第一句sql使得框架封装以后实现分页效果
分页

------解决方案--------------------

WITH query AS (
SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ 
FROM ( 
select TOP(40) *  from (
select legal_entity_id,process_date,record_id,amount from engine_fp where process_date='2013-06-25'
) s pivot (max(amount) for record_id in([23],[24],[25],[26],[27],[28],[29],[30],[31],[33],[34],[38])) 
c order by legal_entity_id 
) inner_query 

) SELECT legal_entity_id,process_date,record_id,amount 
FROM query WHERE __hibernate_row_nr__ >= 20 AND __hibernate_row_nr__ < 40

这样呢?
------解决方案--------------------