您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在SQL Server查询中查找哪些产品与其他产品一起卖得很好

如何在SQL Server查询中查找哪些产品与其他产品一起卖得很好

我认为应该这样做

SELECT P1.Product_Code,
       P2.Product_Code,
       Count(DISTINCT S1.SALE_ID)
FROM   Product P1
       JOIN Product P2
         ON P1.Product_Code > P2.Product_Code
       LEFT JOIN Sales S1
                 INNER JOIN Sales S2
                   ON S1.SALE_ID = S2.SALE_ID
         ON S1.Product_Code = P1.Product_Code
            AND S2.Product_Code = P2.Product_Code
GROUP  BY P1.Product_Code,
          P2.Product_Code
SQLServer 2022/1/1 18:53:08 有315人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶