赞
踩
- select *
- from (
- select *
- from company_info
- where company_name = 'xxxxx科技有限公司'
- order by create_time desc
- ) t
- group by t.department;
错误方式原因: 当子查询的order by语句后面没有limit关键字时,数据库会自动优化,即忽略order by语句。因此只需要添加limit关键字即可。
1. 第一种sql 估摸了下数据,肯定不会超过2000。所以设置的2000
- SELECT
- t.id, t.title
- FROM
- (
- SELECT * FROM tb_test ORDER BY update_time DESC LIMIT 2000
- ) t
- GROUP BY
- t.type
2. 第二种sql
- SELECT
- t.id,
- t.period_title
- FROM
- (
- SELECT
- DISTINCT id, period_title, course_id
- FROM
- tb_aca_video_record
- WHERE
- order_no IN ( '31', '32', '33', '34', "35" )
- AND course_id IN ( 2, 3, 4, 5,6 )
- AND user_id = 105
- ORDER BY
- update_time DESC
- ) t
- GROUP BY
- t.course_id
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。