读书人

队列转换后分页出错求帮组

发布时间: 2013-07-01 12:33:04 作者: rapoo

行列转换后分页出错,求帮组,急急急!!!
这是我行列转换的的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

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


WITH query AS (
SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__
FROM (
select TOP(40) 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
) inner_query

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

读书人网 >SQL Server

热点推荐