<bdo id='TdExB'></bdo><ul id='TdExB'></ul>

      1. <small id='TdExB'></small><noframes id='TdExB'>

        <tfoot id='TdExB'></tfoot>

        <legend id='TdExB'><style id='TdExB'><dir id='TdExB'><q id='TdExB'></q></dir></style></legend>
        <i id='TdExB'><tr id='TdExB'><dt id='TdExB'><q id='TdExB'><span id='TdExB'><b id='TdExB'><form id='TdExB'><ins id='TdExB'></ins><ul id='TdExB'></ul><sub id='TdExB'></sub></form><legend id='TdExB'></legend><bdo id='TdExB'><pre id='TdExB'><center id='TdExB'></center></pre></bdo></b><th id='TdExB'></th></span></q></dt></tr></i><div id='TdExB'><tfoot id='TdExB'></tfoot><dl id='TdExB'><fieldset id='TdExB'></fieldset></dl></div>

        mySQL 返回每个类别的前 5 个

        时间:2023-06-03
        <legend id='s2535'><style id='s2535'><dir id='s2535'><q id='s2535'></q></dir></style></legend>

          • <bdo id='s2535'></bdo><ul id='s2535'></ul>

            <i id='s2535'><tr id='s2535'><dt id='s2535'><q id='s2535'><span id='s2535'><b id='s2535'><form id='s2535'><ins id='s2535'></ins><ul id='s2535'></ul><sub id='s2535'></sub></form><legend id='s2535'></legend><bdo id='s2535'><pre id='s2535'><center id='s2535'></center></pre></bdo></b><th id='s2535'></th></span></q></dt></tr></i><div id='s2535'><tfoot id='s2535'></tfoot><dl id='s2535'><fieldset id='s2535'></fieldset></dl></div>
                <tbody id='s2535'></tbody>

              1. <small id='s2535'></small><noframes id='s2535'>

                1. <tfoot id='s2535'></tfoot>
                  本文介绍了mySQL 返回每个类别的前 5 个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望能够为每个菜单返回 5 个菜单项.我试过这几个脚本,但没有运气.这是桌子

                  I want to be able to return 5 menuitem per menu. I've tried this several script but had no luck. here are the tables

                  menus
                  -------
                  menuid int()
                  profileName varchar(35)
                  
                  menuitems
                  -----------
                  itemid int()
                  name varchar(40)
                  

                  这是我现在拥有的.我收到以下脚本的错误消息.错误:子查询返回多于 1 行.

                  Here what I have now. I'm getting the error message with the script below. Error: Subquery returns more then 1 row.

                  SELECT m.profilename, name
                  FROM menus m 
                  WHERE (SELECT name
                          from menuitems s
                          where m.menuid = s.menuid
                          limit 5)
                  

                  非常感谢任何建议.

                  推荐答案

                  你必须为此使用副作用变量

                  You have to use side effecting variables for this

                  SELECT profilename, name
                  FROM
                  (
                      SELECT m.profilename, s.name,
                          @r:=case when @g=m.profilename then @r+1 else 1 end r,
                          @g:=m.profilename
                      FROM (select @g:=null,@r:=0) n
                      cross join menus m 
                      left join menuitems s on m.menuid = s.menuid
                  ) X
                  WHERE r <= 5
                  

                  这篇关于mySQL 返回每个类别的前 5 个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL 过去 12 个月的每月销售,包括没有销售的月份 下一篇:违反完整性约束:1452 无法添加或更新子行:

                  相关文章

                  <tfoot id='RKEaw'></tfoot>

                  1. <legend id='RKEaw'><style id='RKEaw'><dir id='RKEaw'><q id='RKEaw'></q></dir></style></legend>
                  2. <small id='RKEaw'></small><noframes id='RKEaw'>

                    <i id='RKEaw'><tr id='RKEaw'><dt id='RKEaw'><q id='RKEaw'><span id='RKEaw'><b id='RKEaw'><form id='RKEaw'><ins id='RKEaw'></ins><ul id='RKEaw'></ul><sub id='RKEaw'></sub></form><legend id='RKEaw'></legend><bdo id='RKEaw'><pre id='RKEaw'><center id='RKEaw'></center></pre></bdo></b><th id='RKEaw'></th></span></q></dt></tr></i><div id='RKEaw'><tfoot id='RKEaw'></tfoot><dl id='RKEaw'><fieldset id='RKEaw'></fieldset></dl></div>

                    • <bdo id='RKEaw'></bdo><ul id='RKEaw'></ul>