记录没有按group by子句分组?

时间:2014-10-13 07:53:11

标签: sql oracle group-by

我有以下表格:

pkey - pval

one - dfgf
two - dg 
three - asf
one - asarset
three - se

查询

select pkey,pval from dummy11 group by pkey,pval

返回以下输出..

pkey  -    pval
three  -   asf
one   -   asarset
three -    se
one   -   dfgf
two    -  dg

为什么不是grouped by pkey,pval

我希望输出使用order by

select pkey,pval from dummy11 order by pkey,pval

但这与在这种情况下使用group by不一样吗?

1 个答案:

答案 0 :(得分:0)

Why is it not grouped by pkey,pval ?

答案:按照您的意见,您期待GROUP BY无法做到的事情。

I want the output as how it comes by using order by

select pkey,pval from dummy11 order by pkey,pval
But isn't that the same thing as using group by in this case?
答:不,这不是一回事。 ORDER BY对输出进行排序,GROUP BY不对输出进行排序

GROUP BY条款:

"groups a result into subsets that have matching values for one or more columns. "

oracle docs