lzh022217的gravatar头像
lzh0222172015-06-07 12:20:47

上海快三3d开奖号码今天:Mysql按某个字段实现分组统计Top5 Sql语法查询语句

上海快三今日开奖走势国结果 www.6r52v.cn SET @id:= 0,@type1:= '';

SELECT dsx.row_number, dsx.type, dsx.type_name, dsx.SKU, dsx.number
FROM
(
SELECT b.type, b.type_name, b.SKU, b.number,
       @id:= IF(@type1 = type,@id+1,1) as row_number, @type1:= type
FROM

   SELECT a.type, a.type_name, a.SKU, a.number
   FROM
   (
    SELECT "01" AS type,"01类别" AS type_name, "00000001" AS SKU, 213 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000002" AS SKU, 234 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000003" AS SKU, 345 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000004" AS SKU, 454 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000005" AS SKU, 223 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000006" AS SKU, 123 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000007" AS SKU, 321 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000008" AS SKU, 741 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000009" AS SKU, 463 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000010" AS SKU, 127 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000011" AS SKU, 147 AS number UNION ALL
    SELECT "01" AS type,"01类别" AS type_name, "00000012" AS SKU, 134 AS number UNION ALL
    SELECT "02" AS type,"02类别" AS type_name, "00000013" AS SKU, 129 AS number UNION ALL
    SELECT "02" AS type,"02类别" AS type_name, "00000014" AS SKU, 342 AS number UNION ALL
    SELECT "02" AS type,"02类别" AS type_name, "00000015" AS SKU, 232 AS number UNION ALL
    SELECT "02" AS type,"02类别" AS type_name, "00000016" AS SKU, 444 AS number UNION ALL
    SELECT "02" AS type,"02类别" AS type_name, "00000017" AS SKU, 555 AS number UNION ALL
    SELECT "02" AS type,"02类别" AS type_name, "00000018" AS SKU, 666 AS number UNION ALL
    SELECT "02" AS type,"02类别" AS type_name, "00000019" AS SKU, 332 AS number UNION ALL
    SELECT "02" AS type,"02类别" AS type_name, "00000020" AS SKU, 234 AS number UNION ALL
    SELECT "02" AS type,"02类别" AS type_name, "00000021" AS SKU, 532 AS number UNION ALL
    SELECT "03" AS type,"03类别" AS type_name, "00000022" AS SKU, 121 AS number UNION ALL
    SELECT "03" AS type,"03类别" AS type_name, "00000023" AS SKU, 231 AS number UNION ALL
    SELECT "03" AS type,"03类别" AS type_name, "00000024" AS SKU, 875 AS number UNION ALL
    SELECT "03" AS type,"03类别" AS type_name, "00000025" AS SKU, 587 AS number UNION ALL
    SELECT "03" AS type,"03类别" AS type_name, "00000026" AS SKU, 569 AS number UNION ALL
    SELECT "03" AS type,"03类别" AS type_name, "00000027" AS SKU, 487 AS number UNION ALL
    SELECT "03" AS type,"03类别" AS type_name, "00000028" AS SKU, 478 AS number UNION ALL
    SELECT "03" AS type,"03类别" AS type_name, "00000029" AS SKU, 587 AS number UNION ALL
    SELECT "03" AS type,"03类别" AS type_name, "00000030" AS SKU, 789 AS number 
   ) AS a
   ORDER BY a.type, a.number DESC
) AS b
) AS dsx
WHERE dsx.row_number <=5


打赏

顶部客服微信二维码底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友
  • 农业农村部2017年返乡下乡双创人员达740万人 2019-04-24
  • A站受黑客攻击:近千万条用户数据外泄 涉ID及密码等 2019-03-29
  • 语文水平太差,直通通的转不弯来,又怎么表现逻辑大师的水平,忽悠成为自我暴露 2019-03-25
  • 亚冠-曾诚神扑救主 中超德比权健主场0-0恒大 2019-03-25
  • 看好啦!是时候表演真正的技术了 2019-03-16
  • 楼市下半年或持续降温 房地产长效机制加速推进 2019-03-16
  • “世界杯时间”,以独特方式展现中国元素 2019-01-11
  • 香港迪士尼推“无现金”体验便利游客 2019-01-11
  • 华媒:荷兰超市提倡减少使用一次性塑料制品 2018-07-13
  • 抓住党的建设着力点,焕发全党蓬勃活力  2018-07-12
  • 湖州市从细从实依法治路 2018-07-12
  • 【新时代 新作为 新篇章】“煤老大”渐行渐远 新动能清风徐来 2018-07-11
  • 西部网(陕西新闻网)www.cnwest.com 2018-07-11
  • 平凡人生闪耀璀璨的生命光华——“中国网事·感动2017”颁奖典礼侧记 2018-07-10
  • 为什么截留信马克的帖子?这还有摆事实讲道理存在吗? 2018-07-10
  • 808| 630| 161| 841| 387| 729| 579| 991| 515| 202|