sql 排序并分页的问题 ,求高手解答。
with z1 as (select *,row_number() over(order by Csi_id asc ) as a,
from CarSourceInformation where 1=1 )
z2 as (select *,row_number() over(order by Vehicle_ID) as b
from Vehicle where 1=1 ),
z3 as (select M_id,M_Credit,M_Code,row_number() over(order by M_ID) as c from Member where 1=1 )
select CarSourceInformation.*,Vehicle.*,Member.M_ID,Member.M_Credit,Member.M_Code from z1 CarSourceInformation,z2 Vehicle ,z3 Member
where CarSourceInformation.Csi_VIN = Vehicle.Vehicle_ID and CarSourceInformation.Csi_Member = Member.M_Code
and a between 1 and 16
order by Member.M_Credit
这是我原来的sql 但是未能实现对Member.M_Credit 排序,“and a between 1 and 16
”为分页,求高手指点!!!
------解决方案--------------------
SQL code
with z1 as
(select *,row_number() over(order by Csi_id asc ) as a --, 这个位置多了一个逗号
from CarSourceInformation where 1=1 ), --) 这个位置的括号应该是半角的
z2 as (select *,row_number() over(order by Vehicle_ID) as b
from Vehicle where 1=1 ),
z3 as (
select M_id,M_Credit,M_Code,row_number() over(order by M_ID) as c from Member where 1=1 ) --1=1 没有意思了
select
CarSourceInformation.*,
Vehicle.*,
Member.M_ID,Member.M_Credit,Member.M_Code
from z1 CarSourceInformation,z2 Vehicle ,z3 Member
where CarSourceInformation.Csi_VIN = Vehicle.Vehicle_ID
and CarSourceInformation.Csi_Member = Member.M_Code
and z1.a between 1 and 16
order by Member.M_Credit