mysql的in选择结果过,按照in里面的排序排序
2016-01-25 17:42
691 查看
因为如果不用下面的order by field(列名字,数字),则结果是按照id的自然干顺序排的
只有加了下面的order by 后才是按照in里面的顺序排序!
select user.us_fansno as '号',sub.usb_score as '积分'
from b_user user,b_usersub sub
where user.us_id = sub.us_id
and user.us_fansno in (
28296 ,
1802568 ,
1167907 ,
331085 ,
32336 ,
608608 ,
2036032 ,
875829 ,
2098730 ,
1988862
)
order by field(
user.us_fansno,
28296 ,
1802568 ,
1167907 ,
331085 ,
32336 ,
608608 ,
2036032 ,
875829 ,
2098730 ,
1988862
);
只有加了下面的order by 后才是按照in里面的顺序排序!
select user.us_fansno as '号',sub.usb_score as '积分'
from b_user user,b_usersub sub
where user.us_id = sub.us_id
and user.us_fansno in (
28296 ,
1802568 ,
1167907 ,
331085 ,
32336 ,
608608 ,
2036032 ,
875829 ,
2098730 ,
1988862
)
order by field(
user.us_fansno,
28296 ,
1802568 ,
1167907 ,
331085 ,
32336 ,
608608 ,
2036032 ,
875829 ,
2098730 ,
1988862
);
相关文章推荐
- Mysql中创建根据第二个自增的id
- MySQL某一时间点数据与一小时前、一天前、一月前数据对比
- ubantu操作指令 访问Mysql
- MYSQL的分区字段必须包含主键-介绍以及解决方法
- mysql 索引( mysql index )
- 使用mysql profiling功能剖析单条查询
- mysql解决自动断开8小时未曾用过的链接
- [MySQL]Software caused connection abort: recv failed 问题分析与解决
- PostgreSQL与MySQL优势比较
- PostgreSQL与MySQL优势比较
- [MySQL]Software caused connection abort: recv failed 问题分析与解决
- mysql解决自动断开8小时未曾用过的链接
- MAC 下配置MySQL
- 怎么跳出MySQL的10个大坑
- 【转】优化MySQL语句的十个建议
- 【转】优化MySQL语句的十个建议
- mysql update语句问题:You can't specify target table 'user' for update in FROM clause
- 解决mysql出现“the table is full”的问题
- 解决mysql出现“the table is full”的问题
- mysql update语句问题:You can't specify target table 'user' for update in FROM clause