I use variable to do it


  • 2
    L
    SELECT 
      * 
    FROM
      stadium 
    WHERE INSTR(
        (SELECT CONCAT(',',GROUP_CONCAT(tmpaa.ids),',') AS ids FROM (SELECT 
          GROUP_CONCAT(id) AS ids
        FROM
          (SELECT 
            id,
            CASE
              WHEN (
                (@prevone := people) < 100 
                OR (@prevone >= 100 
                  AND @prevtwo < 100)
              ) 
              THEN @group := @group + 1 
              ELSE @group := @group 
            END AS groupno,
            (@prevtwo := people) AS bb 
          FROM
            stadium,
            (SELECT 
              @group := 0,
              @prevone := - 1,
              @prevtwo := - 1) init) AS tmp 
        GROUP BY tmp.groupno 
        HAVING COUNT(1) >= 3 ) AS tmpaa),
        CONCAT(',', id, ',')
      ) > 0
    

  • 0
    J

    I think it's a very good solution. But I'm not sure how do you assign @prevTwo and @prevone to different values, they are all assigned by := people in the same subquery, should they all get assigned to prevone?
    Thanks!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.