在mysql中类似oracle的rowid
SELECT @rowNum:=@rowNum + 1 AS ‘行号’,a.* FROM constellation_keywords_info a,(SELECT @rowNum:=0) b;
mysql取分组前3条记录,(性能极差)
https://blog.csdn.net/Jacksun_huang/article/details/88869025
(性能极差)
select a.,count() as num from constellation_analysis_info as a
inner join constellation_analysis_info as b ON a.constellation_code=b.constellation_code
where b.id>=a.id group by a.id having num<=3
MySQL中利用简单SQL实现开窗函数的分组排序功能 (性能极好)
https://jingyan.baidu.com/article/d8072ac48d2730ec94cefd43.html?qq-pf-to=pcqq.c2c
<resultMap id=”allDreamResultMap” type=”tk.mybatis.springboot.vo.AllDreamVo”>
<result column=”dream_type” jdbcType=”INTEGER” property=”dreamType” />
<result column=”description” jdbcType=”VARCHAR” property=”description” />
<collection ofType=”tk.mybatis.springboot.vo.DreamParentLableVo” property=”parentLabeList”>
<result column=”id” jdbcType=”BIGINT” property=”id” />
<result column=”label” jdbcType=”VARCHAR” property=”label” />
</collection>
</resultMap>
<select id=”getAllDream” resultMap=”allDreamResultMap”>
SELECT
t1.dream_type,
t1.description,
t2.id,
t2.label
FROM
dream_type_info t1
left join (
SELECT id,dream_type,label,new_rank as rank from
(SELECT id,dream_type,label,
IF(@tmp=dream_type,@rank:=@rank + 1,@rank:=1) as new_rank,
@tmp:=dream_type as tmp FROM
dream_parent_lable a
) b
where new_rank <![CDATA[ <= ]]> 20
)t2 ON t2.dream_type = t1.dream_type
order by t1.dream_type asc
</select>