0

我有一个像下面这样的查询,它从两个表中提取类别数据,

SELECT pc.productCategoryId, pcs.parentCategoryId, pc.categoryId
FROM productCategory AS pc
LEFT JOIN productCategories AS pcs ON pcs.categoryId = pc.categoryId
WHERE pc.productId =110
ORDER BY pc.categoryId

这就是结果

productCategoryId parentCategoryId categoryId Ascending
225               0                1
773               1                1283
773               132              1283
774               1283             10314

但这是想要的结果

productCategoryId parentCategoryId categoryId Ascending
    225               0                1
    773               1                1283
    774               1283             10314

我的目标是保留与以下父类别 ID 匹配的记录,因此应该以某种方式取出第三个。我的意思是每个以前的记录 categoryid 应该匹配下一个的 parentcategoryId

4

0 回答 0