sql之分组查询

时间:2021-06-25 09:53:34

错误示例

select  PMId,GJTypeId,GJXHCode,GJMonomer,GJFloor,GJLong,GJWidth,GJHigh, convert(decimal(18,4),GJFL) AS GJFL,count(1) GJSum from GJ_ProjectGJ 
where PMId=2155 and GJMonomer='4#' and GJXHCode='YB48.24.1' 
group by PMId,GJTypeId,GJXHCode,GJMonomer,GJFloor,GJLong,GJWidth,GJHigh,GJFL

正确示例

select  PMId,GJTypeId,GJXHCode,GJMonomer,GJFloor,GJLong,GJWidth,GJHigh, convert(decimal(18,4),GJFL) AS GJFL,count(1) GJSum from GJ_ProjectGJ 
where PMId=2155 and GJMonomer='4#' and GJXHCode='YB48.24.1' 
group by PMId,GJTypeId,GJXHCode,GJMonomer,GJFloor,GJLong,GJWidth,GJHigh,convert(decimal(18,4),GJFL)

 一点小差池,会导致显示的数据出现问题