mysql 特殊用法

在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>

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

推荐阅读更多精彩内容

  • 如何将小表放入keep池中? alter table xxx storage(buffer_pool keep);...
    一点也不想吃辣阅读 416评论 0 2
  • /+NOCACHE(TABLE)/当进行全表扫描时,CACHE提示能够将表的检索块放置在缓冲区缓存中最近最少列表L...
    一点也不想吃辣阅读 475评论 0 1
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,545评论 0 13
  • MySQL语句大全(超详细) 1、说明:创建数据库 CREATE DATABASE database-name 2...
    Ncompass阅读 320评论 0 1
  • 为什么我在家里教,孩子还是特别希望能去培训班呢?每次看到他之前在培训班跟我一起上课的图片,马上就说妈妈我们去上课吧...
    姚Fay阅读 111评论 0 0