如何让DISTINCT函数只查看一列?
SELECT DISTINCT
id AS uniqueid,
ProductCode AS ProductID,
DisplayName AS ReportingLabel,
REPLACE(URL, 'http', 'https') AS URL,
ProductCategory AS Category,
Description,
CONCAT('https://', ImageURL) AS Image,
latestSellingPrice AS Price,
Brand,
IF(latestSellingPrice > 300,
'TRUE',
'FALSE') AS Is_Default,
IF(StockAvailable > 0, 'TRUE', 'FALSE') AS InStock
FROM
XML_Import_Server
WHERE
Brand = 'Totalsports'
AND
DisplayName <> 'eGift Card'
由于尺寸和颜色选项,ProductCode并不总是唯一的。但我只需要拉出它的第一个变体。
答案 0 :(得分:1)
你可以使用聚合功能和分组 例如,对于某些列
SELECT DISTINCT
id AS uniqueid,
min(ProductCode) AS ProductID,
DisplayName AS ReportingLabel
FROM
XML_Import_Server
WHERE
Brand = 'Totalsports'
AND
DisplayName <> 'eGift Card'
group by id, DisplayName
答案 1 :(得分:1)
第一个变种并不清楚你的意思。所以我猜你的意思是具有最低import {
Col,
Navbar,
Nav,
NavItem
} from 'react-bootstrap'
值的变体。
使用加入主表的子查询执行此操作。子查询查找相关的id
值。
id
尝试这样说服自己,它为每个不同的 SELECT MIN(id) id
FROM XML_Import_Server
GROUP BY ProductCode
值提供了正确的选择。
然后,将其加入主查询。
ProductCode