select * from (select .... from ca_applicant_info cai,ca_order_info coi
where coi.USERID = cai.id and coi.ispay=1 and coi.delflag=0 and coi.state=0
)wk where wk.rn> 0 and wk.rn<=2
order by createdate DESC
这样子写 只能取出前两条记录再进行排序的~~~那不对了!!!我是想 排序后 取出头两天记录的~~~有哪位兄弟知道的 帮下忙哈
------解决方案--------------------
- SQL code
SELECT *FROM ( SELECT ... FROM ca_applicant_info cai , ca_order_info coi WHERE coi.USERID = cai.id AND coi.ispay = 1 AND coi.delflag = 0 AND coi.state = 0 ORDER BY createdate DESC --写到这儿 ) wkWHERE wk.rn > 0 AND wk.rn <= 2
------解决方案--------------------
SELECT *
FROM (SELECT Cai.*,Coi.* ,row_number()over(ORDER BY Cai/Coi.Createdate) rn
FROM Ca_Applicant_Info Cai, Ca_Order_Info Coi
WHERE Coi.Userid = Cai.Id
AND Coi.Ispay = 1
AND Coi.Delflag = 0
AND Coi.State = 0
) Wk
WHERE Wk.Rn > 0
AND Wk.Rn <= 2
--ORDER BY Createdate DESC
------解决方案--------------------
不是太明确lz的问题点。
还是请LZ 给表结构,数据,和要求的结果样式吧。
------解决方案--------------------
------解决方案--------------------