SQL查询优化:过滤掉ItemType为0且item_SUM小于50的数据
SELECT PlayerId, itemcfg.ItemType, SUM(Count) as item_SUM FROM item LEFT JOIN itemcfg ON itemcfg.Id = item.ItemCfgId WHERE 1=1 GROUP BY PlayerId, ItemType HAVING (itemcfg.ItemType <> 0 OR item_SUM >= 50) ORDER BY item_SUM DESC; 如何使查询结果过滤掉item.itemtype为0时,item_SUM小于50的数据内容:您可以在查询结果中使用HAVING子句来过滤掉item.itemtype为0且item_SUM小于50的数据。以下是修改后的查询语句: SELECT PlayerId, itemcfg.ItemType, SUM(Count) as item_SUM FROM item LEFT JOIN itemcfg ON itemcfg.Id = item.ItemCfgId WHERE 1=1 GROUP BY PlayerId, ItemType HAVING (itemcfg.ItemType <> 0 OR item_SUM >= 50) ORDER BY item_SUM DESC; 这样,查询结果将只包含item.itemtype不为0或item_SUM大于等于50的数据。
原文地址: https://www.cveoy.top/t/topic/qdqI 著作权归作者所有。请勿转载和采集!