分页查询SQL的处理问题

在分页查询count时候,order by 会被去掉,但是如果在sql中要使用 over() 分析函数,order by 被去掉显然是不合理的,要如何避免呢

2.png

评论区

暴风雪

2017-03-02 10:54

暴风雪

2017-03-02 10:55

String totalRowSql = "select count(*) " + config.dialect.replaceOrderBy(sqlExceptSelect);

lyh061619

2017-03-02 11:27

外层再套一层select*如:
String select = "select a2.*";
String form = " from(select a.id, a.number, a.name, a.desc, date_format(a.creat e_at, '%Y-%m-%d') createAt, " +
"(select count(id) amount from goods where dept_id = a.id) amount from goods a) a2 where 1=1";
String orderBy = " order by a2.create_at, a2.amount desc ";

JFinal

2017-03-02 12:33

jfinal 3.0 已然没有去掉 order by 了,你试试

暴风雪

2017-03-02 14:47

@lyh061619 @JFinal 多谢指点 后面应该会考虑升级 现在还是牺牲效率改写了SQL

热门反馈

扫码入社