Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

Melewati output dari nilai yang identik di baris berikutnya

DECLARE @tblABC TABLE
(
    SrNo INT, [Date] DATETIME, BillNo CHAR(5), Amount DECIMAL(10,2)
);

INSERT @tblABC SELECT 1,'20120210','VAT-1',1200.00
UNION ALL SELECT 2,'20120210','RET-4',50.00
UNION ALL SELECT 3,'20120210','RET-5',150.50
UNION ALL SELECT 4,'20120211','VAT-2',1500.00
UNION ALL SELECT 5,'20120211','RET-6',2505.00
UNION ALL SELECT 6,'20120212','VAT-3',05.00;

;WITH x AS 
(
  SELECT SrNo, [Date] = REPLACE(CONVERT(CHAR(10), [Date], 103), '/', '-'), 
    BillNo, Amount, rn = ROW_NUMBER() OVER (PARTITION BY [Date] ORDER BY SrNo)
    FROM @tblAbC
)
SELECT SrNo, [Date] = CASE rn WHEN 1 THEN [Date] ELSE '' END, BillNo, Amount
  FROM x 
  ORDER BY SrNo;


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Klausa OrderBy menghasilkan set hasil yang berbeda ketika kolom pesanan memiliki data yang sama

  2. Daftar identitas sisipan SQL Server

  3. Permintaan DateTime hanya pada tahun di SQL Server

  4. Cara Memulihkan Database SQL Server di Mac menggunakan Azure Data Studio

  5. Kinerja GUID