mysql select to return blanks for all but first row of repeating column

前端 未结 5 643
独厮守ぢ
独厮守ぢ 2020-12-21 14:17

Is it possible to create a mysql select (directly or using a stored procedure) that will return blanks for repeating columns. For example, a select that would normally retu

5条回答
  •  悲&欢浪女
    2020-12-21 14:32

    For MySQL (I guess it should be similar for other DBs), to avoid repeating a column value on every row, you can make good use of variables. No subqueries necessary: light and quick.

    //Init a variable
    SET @previous:="";
    
    //Remember previous row value
    SELECT IF(Name=@previous, "", @previous:=Name) AS GroupedName, Value
    FROM tableName ORDER BY 1;
    

提交回复
热议问题