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

Tampilan SQL Penjualan Tanggal Paralel

Untuk penjualan pelanggan di tahun yang berbeda.

Demo Fiddle SQL

SELECT DimCustomer.CustomerName,
       VW_Current.Saledate,
       VW_Current.ParallelDate,
       VW_Current.CurrentSales,
       VW_Previous.CurrentSales as ParallelSale

FROM   DimCustomer 
       INNER JOIN VW_ParallelSales VW_Current
           ON DimCustomer.CustomerKey = VW_Current.CustomerKey
       LEFT JOIN VW_ParallelSales VW_Previous
           ON VW_Current.ParallelDate = VW_Previous.Saledate
          AND DimCustomer.CustomerKey = VW_Previous.CustomerKey
ORDER BY 1, 2            

Untuk kunci produk

Demo Fiddle SQL

With sales as (
    SELECT 
           DimProduct.ProductKey,
           DimProduct.ProductName,
           VW_ParallelSales.Saledate,
           VW_ParallelSales.ParallelDate,
           VW_ParallelSales.CurrentSales,
           VW_ParallelSales.ParallelSales
    FROM   DimProduct INNER JOIN VW_ParallelSales ON DimProduct.ProductKey = 
           VW_ParallelSales.ProductKey
)
SELECT 
   s_recent.ProductName,
   s_recent.Saledate ThisYear,
   s_old.Saledate PreviousYear,
   s_recent.CurrentSales CurrentSales,
   s_old.CurrentSales ParallelSales
FROM 
    SALES s_recent 
    left outer join SALES s_old 
        on s_recent.saledate = s_old.saledate + 10000
       and s_recent.ProductKey = s_old.ProductKey



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Berurusan dengan NULL di SQL Server

  2. Antrian dalam Pesan WCF OneWay menggunakan Layanan Windows dan SQL Server

  3. SQL Server Menjalankan Pemantauan Kueri

  4. Buat Profil Email Database (SSMS)

  5. Salinan kaskade baris dalam sql