为什么我的SQL这么菜

happyuser 2002-04-21 09:42:53
select tab1.a,tab2.b from tab1,tab2 where tab1.c=tab2.d group by tab1.a

为什么不能进行分组查询?
...全文
17 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jugular_Phoenix 2002-04-22
  • 打赏
  • 举报
回复
有用聚组函数sum()就得用group by指明如何聚组
举个例:
select tab1.a,table2.b,sum(tab1.e),sum(tab2.f)
from tab1,tab2
where tab1.c=tab2.d
group by tab1.a,tab2.b,tab1.c,tab2.d;
happyuser 2002-04-21
  • 打赏
  • 举报
回复
thlong(江米小枣):不好意思,我的实际写法中是有sum()等函数的,但还是不行啊
KingSunSha 2002-04-21
  • 打赏
  • 举报
回复
当然不能,你哪里用到分组了?
select tab1.a,tab2.b from tab1,tab2 where tab1.c=tab2.d group by tab1.a, tab2.b;
从语法上讲是可以得,但是不如
select distinct tab1.a,tab2.b from tab1,tab2 where tab1.c=tab2.d;

不明白你要的结果是什么
thlong 2002-04-21
  • 打赏
  • 举报
回复
因为你的GROUP BY中包含非分组函数
例如:
select tab1.a,tab2.b,count(*) from tab1,tab2 where ta1.c=tab2.c group by tab1.a,tab2.b

2,596

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧