双排名

set @row_num = #{offset};

select result.*, @row_num := @row_num+ 1 AS ranking from

(

SELECT

vi.*,vt.tname,ui.nick_name

FROM

video_topic_belong vtb

LEFT JOIN

video_info vi ON vtb.video_id = vi.video_id

left join

video_type vt on vi.type_id=vt.type_id

left join

user_info  ui  on ui.user_id=vi.user_id

<where>

<if test="videoId != null and videoId.trim() != ''">

and vi.`video_id` = #{videoId}

</if>

<if test="userId != null and userId.trim() != ''">

and vi.`user_id` = #{userId}

</if>

<if test="nickName != null and nickName.trim() != ''">

and ui.nick_name like concat("%",#{nickName},"%")

</if>


and vi.create_time >= str_to_date('2018-10-15', '%Y-%m-%d')

]]>


and vi.create_time <= str_to_date('2018-11-23', '%Y-%m-%d')

]]>

AND    is_private = 1

AND    vi.statues = 1

AND    vtb.topic_id = (

SELECT

topic_id

FROM

video_topic

WHERE

tname = 'ThanksToYou'

)

</where>

<choose>

<when test="sidx != null and sidx.trim() != ''">

order by vi.${sidx} ${order}

</when>

<otherwise>

order by vi.collection_num,vi.comment_num

</otherwise>

</choose>

LIMIT #{offset}, #{limit}

) as result

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 友谊究竟存活多久?有没有一个时间期限? 我个人觉得友谊也要分为在哪个时代? 要是在古代,可能友谊长存,而在这个浮躁...
    痞马阅读 214评论 0 0
  • 本来是很想上色的,可怎么也没有达到自己的理想,就放弃了。慢慢摸索吧。
    美线阅读 69评论 1 1
  • 1. 创建一个名为compamy的数据库,并设置字符集charset为utf82. 在该数据库下设计一个员工表(e...
    叫我老村长阅读 362评论 0 1
  • 千言万语,不知从何说起?总之是难受。 动手记录2018年西决最后一篇感受,想过几个标题,诸如“命运的轮回”“休斯顿...
    二羽_ba63阅读 1,556评论 0 0