ORACLE,为什么子查询中SELECT数可以大于GROUP BY 10
举例如下:selectt.purchasecode,t.afrom(SELECTcoun.purchasecode,coun.scandate,count(*)aFROM...
举例如下:
select t.purchasecode,
t.a
from (
SELECT coun.purchasecode,
coun.scandate,
count(*) a
FROM APP_COUNTERFOIL COUN
group by COUN.PURCHASECODE
)
这种情况是对的,但是
coun.scandate,
count(*) a
FROM APP_COUNTERFOIL COUN
group by COUN.PURCHASECODE
这种情况是错的,为什么?
修正一下,第二个SQL应该是
coun.scandate,
count(*) a
FROM APP_COUNTERFOIL COUN
group by COUN.PURCHASECODE 展开
select t.purchasecode,
t.a
from (
SELECT coun.purchasecode,
coun.scandate,
count(*) a
FROM APP_COUNTERFOIL COUN
group by COUN.PURCHASECODE
)
这种情况是对的,但是
coun.scandate,
count(*) a
FROM APP_COUNTERFOIL COUN
group by COUN.PURCHASECODE
这种情况是错的,为什么?
修正一下,第二个SQL应该是
coun.scandate,
count(*) a
FROM APP_COUNTERFOIL COUN
group by COUN.PURCHASECODE 展开
3个回答
展开全部
你举的这两个例子都是错的,group by后的分组列必需小于等于select 后的分组列
追问
实际上是可以运行的,第二个写错了,应该是
select coun.purchasecode,
count(*) a
FROM APP_COUNTERFOIL COUN
group by COUN.PURCHASECODE
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
coun.scandate,
count(*) a
FROM APP_COUNTERFOIL COUN
group by COUN.PURCHASECODE
这段代码中你前面查询的没有要分组的字段
count(*) a
FROM APP_COUNTERFOIL COUN
group by COUN.PURCHASECODE
这段代码中你前面查询的没有要分组的字段
追问
第二个错了,是
select coun.purchasecode,
count(*) a
FROM APP_COUNTERFOIL COUN
group by COUN.PURCHASECODE
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
第一种是错误的写法
追问
但是可以运行,怎么回事?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询