sql >> Database teknologi >  >> RDS >> Mysql

SQL - Erstatning af dubletværdi med tom

SELECT Case When Rank=1 then
            `Company`
       Else ''
       End as Company,
       Case When Rank=1 then
            `Date`
       Else ''
       End as `Date`,
       Case When Rank=1 then
            `Paper`
       Else ''
       End as `Paper`, 
       `Condition` 
  FROM (SELECT t.*,
               CASE 
                 WHEN @Company != t.Company OR @Date != t.`Date` OR  @Paper != t.`Paper`
                     THEN @rownum := 1 
                 ELSE @rownum := @rownum + 1 
               END AS rank,
               @Company := t.Company AS var_category,
               @Date := t.`Date` AS var_Date,
               @Paper := t.`Paper` AS var_Paper 
          FROM Table1 t
          JOIN (SELECT @rownum := null, @Company := '') r ) x

Output

Company     Date        Paper   Condition
Company1    19-12-2007  PaperA  Release Second Term
                                Add Third Term
                                Append First Term

Live demo




  1. MySQL - Tæller i gruppe

  2. Hvorfor viser SELECT * FROM tabel INNER JOIN..ON den krydsende søjle to gange?

  3. Sortering af arrays efter dato

  4. Laravel bruger where-sætning på en withCount-metode