Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

SQL - Mengganti Nilai Duplikat Dengan Kosong

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

Keluaran

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

Demo Langsung




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. PHP - Akses MySQL ditolak kesalahan - Bekerja di program lain

  2. Optimalkan kinerja tulis untuk instans AWS Aurora

  3. Masalah SQL:hubungan satu ke banyak dan model EAV

  4. Bagaimana cara menyimpan tanggal dalam milidetik unix di Mysql?

  5. 4 Cara Mendaftar Semua Tabel di Database MySQL