当前使用版本(必填,否则不予处理)

3.1.2

该问题是如何引起的?(确定最新版也有问题再提!!!)

SQL如下:

 select
        TEM.*,
        DETAIL.KeywordType as keywordType,
        DETAIL.Category as Category,
        DETAIL.IsDeleted as deleted,
        DETAIL.CreateTime as createTime,
        DETAIL.ClientId as clientId,
        DETAIL.ZipCode as zipCode,
        DETAIL.IsMonitored as monitored,
        DETAIL.Username as username
        from (
        select
        MKC.Id AS id,
        COUNT(MK.Id) as keywordCount,
        COUNT(MKR.Id) as retailerCount
        from MonitorKeywordCategory MKC
        left join MonitorKeyword MK on MKC.Id = MK.CategoryId
        left join MonitorKeywordCategoryRetailer MKCR on MKCR.CategoryId = MKC.Id
        left join MonitorKeywordRetailer MKR on MKCR.RetailerId = MKR.Id
        WHERE MKC.IsDeleted = 0
        AND MK.IsDeleted = 0
        AND MKCR.IsDeleted = 0
        <if test="params.searchedKeyword!=null and params.searchedKeyword!=''">
            AND MKC.Category LIKE CONCAT('%',#{params.searchedKeyword},'%')
            OR MKC.KeywordType LIKE CONCAT('%',#{params.searchedKeyword},'%')
            OR MK.KeywordText LIKE CONCAT('%',#{params.searchedKeyword},'%')
        </if>
        GROUP BY MKC.Id
        ) TEM left join MonitorKeywordCategory DETAIL
        ON TEM.Id = DETAIL.Id
        <if test="params.pageInfo.orderBy!=null and params.pageInfo.orderBy!=''">
            ORDER BY ${params.pageInfo.orderBy}
        </if>

排序信息是前端传过来的,没有排序传过来的字段是:

重现步骤(如果有就写完整)

不带排序查询的表字段: id,keywordCount,retailerCount,Category,deleted createTime,clientId,zipCode,monitored,username

报错信息(但是id没有重复的)

{ "code": 405, "data": null, "msg": "\r\n### Error querying database. Cause: com.microsoft.sqlserver.jdbc.SQLServerException: Ambiguous column name 'id'.\r\n### The error may exist in file [D:\work_code\microservice-java\criteo\target\classes\mapper\MonitorKeywordCategoryMapper.xml]\r\n### The error may involve defaultParameterMap\r\n### The error occurred while setting parameters\r\n### SQL: WITH selectTemp AS (SELECT TOP 100 PERCENT ROW_NUMBER() OVER (ORDER BY id desc) as row_number, TEM.*, DETAIL.KeywordType as keywordType, DETAIL.Category as Category, DETAIL.IsDeleted as deleted, DETAIL.CreateTime as createTime, DETAIL.ClientId as clientId, DETAIL.ZipCode as zipCode, DETAIL.IsMonitored as monitored, DETAIL.Username as username from ( select MKC.Id AS id, COUNT(MK.Id) as keywordCount, COUNT(MKR.Id) as retailerCount from MonitorKeywordCategory MKC left join MonitorKeyword MK on MKC.Id = MK.CategoryId left join MonitorKeywordCategoryRetailer MKCR on MKCR.CategoryId = MKC.Id left join MonitorKeywordRetailer MKR on MKCR.RetailerId = MKR.Id WHERE MKC.IsDeleted = 0 AND MK.IsDeleted = 0 AND MKCR.IsDeleted = 0 GROUP BY MKC.Id ) TEM left join MonitorKeywordCategory DETAIL ON TEM.Id = DETAIL.Id ORDER BY id desc) SELECT * FROM selectTemp WHERE row_number BETWEEN 1 AND 10 ORDER BY row_number\r\n### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: Ambiguous column name 'id'.\n; bad SQL grammar []; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Ambiguous column name 'id'." }

Comment From: jerryi1

感觉查完count 之后,下面是又一个分页查询?很奇怪看着。 ==> Preparing: SELECT COUNT(1) FROM (SELECT MKC.Id AS id, COUNT(MK.Id) AS keywordCount, COUNT(MKR.Id) AS retailerCount FROM MonitorKeywordCategory MKC LEFT JOIN MonitorKeyword MK ON MKC.Id = MK.CategoryId LEFT JOIN MonitorKeywordCategoryRetailer MKCR ON MKCR.CategoryId = MKC.Id LEFT JOIN MonitorKeywordRetailer MKR ON MKCR.RetailerId = MKR.Id WHERE MKC.IsDeleted = 0 AND MK.IsDeleted = 0 AND MKCR.IsDeleted = 0 GROUP BY MKC.Id) TEM ==> Parameters: <== Columns: <== Row: 2 ==> Preparing: WITH selectTemp AS (SELECT TOP 100 PERCENT ROW_NUMBER() OVER (ORDER BY id desc) as row_number, TEM.*, DETAIL.KeywordType as keywordType, DETAIL.Category as Category, DETAIL.IsDeleted as deleted, DETAIL.CreateTime as createTime, DETAIL.ClientId as clientId, DETAIL.ZipCode as zipCode, DETAIL.IsMonitored as monitored, DETAIL.Username as username from ( select MKC.Id AS id, COUNT(MK.Id) as keywordCount, COUNT(MKR.Id) as retailerCount from MonitorKeywordCategory MKC left join MonitorKeyword MK on MKC.Id = MK.CategoryId left join MonitorKeywordCategoryRetailer MKCR on MKCR.CategoryId = MKC.Id left join MonitorKeywordRetailer MKR on MKCR.RetailerId = MKR.Id WHERE MKC.IsDeleted = 0 AND MK.IsDeleted = 0 AND MKCR.IsDeleted = 0 GROUP BY MKC.Id ) TEM left join MonitorKeywordCategory DETAIL ON TEM.Id = DETAIL.Id ORDER BY id desc) SELECT * FROM selectTemp WHERE row_number BETWEEN 1 AND 10 ORDER BY row_number ==> Parameters: