sql >> Database >  >> RDS >> Mysql

SQL - Dubbele waarde vervangen door leeg

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

Uitgang

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

Live demo




  1. Databasemodellen voor e-commerce Deel 1:De nieuwsbrief

  2. XML-gegevens openen in Oracle

  3. tijdelijk mysql externe toegang uitschakelen

  4. werken met Fluent NHibernate en guid-id's