Jia_Li_z
2019-04-17 15:21
采纳率: 81%
浏览 2.8k
已采纳

达梦数据库的group by 语句出错

SELECT  shop.ID AS 主键,shop.UID AS 用户ID,test.NAME AS 姓名  FROM sysdba.T shop 
LEFT JOIN sysdba.TEST test ON shop.ID = test.ID
WHERE shop.ID > 0
GROUP BY test.NAME;

加上group by 就报错 :无效的SELECT项

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • ꧁gaoKuo꧂ 2019-04-17 15:42
    已采纳

    SELECT max(shop.ID) AS 主键,max(shop.UID) AS 用户ID,test.NAME AS 姓名 FROM sysdba.T shop
    LEFT JOIN sysdba.TEST test ON shop.ID = test.ID
    WHERE shop.ID > 0
    GROUP BY test.NAME;
    或者
    SELECT shop.ID AS 主键,shop.UID AS 用户ID,test.NAME AS 姓名 FROM sysdba.T shop
    LEFT JOIN sysdba.TEST test ON shop.ID = test.ID
    WHERE shop.ID > 0
    GROUP BY test.NAME,shop.ID,shop.UID

    点赞 2 打赏 评论
  • 小胖/老吴 2020-12-10 17:09

    使用GROUP BY的时候,SELECT后只能是分组列和集函数。集函数包括COUNT(*),相异集函数AVG等。

    点赞 打赏 评论

相关推荐 更多相似问题