SQL = "SELECT AUTOFIELDS FROM EFRESH_COMBINED E1, PRODUCTS P1 ,LOCATIONS L1 WHERE E1.AutoDataSet AND E1.PRODCODE = P1.PRODCODE AND E1.LOCATIONID = L1.LOCATIONID(+) AND E1.MERCHANTID = :pMerhcantID AND E1.SERIALNO = :pSerialN AND E1.DATESOLD > to_date('" & Now.AddDays(-QuickSearchShortDay).ToString("yyyy-MM-dd") & "','YYYY-MM-DD') ORDER BY E1.DATESOLD DESC "
我要把这条sql语句 E1.DATESOLD > to_date('" & Now.AddDays(-QuickSearchShortDay).ToString("yyyy-MM-dd") & "','YYYY-MM-DD') 查询出来最新一天的信息改成查询出来最新的10条,需要怎么改sql语句?
如果不考虑性能,可以不限制时间,直接倒序排序后查询的结果再用ROWNUM<=10查询结果。
如果考虑性能,可以考虑用ROWNUM分析函数
哪有那么麻烦呀
SQL = "SELECT top 10 AUTOFIELDS FROM EFRESH_COMBINED E1, PRODUCTS P1 ,LOCATIONS L1 WHERE E1.AutoDataSet AND E1.PRODCODE = P1.PRODCODE AND E1.LOCATIONID = L1.LOCATIONID(+) AND E1.MERCHANTID = :pMerhcantID AND E1.SERIALNO = :pSerialN AND E1.DATESOLD > to_date('" & Now.AddDays(-QuickSearchShortDay).ToString("yyyy-MM-dd") & "','YYYY-MM-DD') ORDER BY E1.DATESOLD DESC "
加上红色部分就行了