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

SQL SELECT beberapa kondisi banyak ke banyak hubungan

SELECT p2p.PageID
FROM
    PageToProduct as p2p
    inner join Product as pr
        on p2p.Product = pr.Product
    inner join PageToProductToRate as p2p2r
        on p2p2r.PageToProductID = p2p.PageToProductID
    inner join ProductRates as r
        on r.ProductRatesID = p2p2r.ProductRatesID 
WHERE
          (pr.Product = 'ALMOND' AND r.CommissionType = 'PREMIUM' AND r.Rate = 0.25) 
      OR  (pr.Product = 'WALNUT' AND r.CommissionType = 'SERVICE FEE' AND r.Rate = 1.25)
      OR  (pr.Product = 'HAZELNUT' AND r.CommissionType = 'EXCESS' AND r.Rate = 1.68)
GROUP BY p2p.PageID
HAVING COUNT(*) = 3; /* requires all three are present, as long as no rows are duplicate */


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Memanggil Prosedur Tersimpan dengan XML Datatype

  2. SQL SUM dari dua tabel yang berbeda

  3. Bagaimana cara langsung mengeksekusi kueri SQL di C #?

  4. Dapatkan catatan 30 hari terakhir dari tanggal hari ini di SQL Server

  5. Bagaimana Anda memodelkan pewarisan secara efektif dalam database?