Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1782042
  • 博文数量: 413
  • 博客积分: 8399
  • 博客等级: 中将
  • 技术积分: 4325
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-09 10:44
文章分类

全部博文(413)

文章存档

2015年(1)

2014年(18)

2013年(39)

2012年(163)

2011年(192)

分类: Mysql/postgreSQL

2014-03-31 21:38:52

下面的sql语句报错:sql错误 (1221) :Incorrect usage of union and order by 

点击(此处)折叠或打开

  1. select * from guojia_jingjia where guanzhi='xxx' order by (aaa+bbb+ccc) desc limit 1
  2. union
  3. select * from guojia_jingjia where guanzhi in (...) order by bbb desc limit 4
  4. union
  5. select * from guojia_jingjia where guanzhi in (...) order by aaa desc limit 4
需要修改成如下:

点击(此处)折叠或打开

  1. select * from (select * from (select * from (select * from guojia_jingjia where guanzhi='xxx' order by (aaa+bbb+ccc) desc limit 1)t1
  2. union
  3. select * from (select * from guojia_jingjia where guanzhi in (...) order by bbb desc limit 4) t2
  4. union
  5. select * from guojia_jingjia where guanzhi in (...) order by aaa desc limit 4

阅读(10829) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~