Include row with out group by [message #625292] |
Sat, 04 October 2014 02:48 |
|
ind!@2020
Messages: 23 Registered: September 2014 Location: India
|
Junior Member |
|
|
Hi All,
How can I include any ename from the same department in the following select query without agregate function.
select deptno,count(*)--any ename from same dept
from emp
group by deptno;
[Updated on: Sat, 04 October 2014 02:49] Report message to a moderator
|
|
|
Re: Include row with out group by [message #625296 is a reply to message #625292] |
Sat, 04 October 2014 04:39 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
And why without aggregate functions? What's wrong with
select deptno,
count(*),
min(ename) -- or max(ename)
from emp
group by deptno
/
Anyway, you could use:
select deptno,
count(*),
(select e2.ename from emp e2 where e2.deptno = e1.deptno and rownum = 1)
from emp e1
group by deptno
/
SY.
[Updated on: Sat, 04 October 2014 04:42] Report message to a moderator
|
|
|
|
|
Re: Include row with out group by [message #625333 is a reply to message #625292] |
Mon, 06 October 2014 03:06 |
John Watson
Messages: 8930 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
ind!@2020 wrote on Sat, 04 October 2014 08:48Hi All,
How can I include any ename from the same department in the following select query without agregate function.
select deptno,count(*)--any ename from same dept
from emp
group by deptno;
You are using COUNT, which is an aggregate function. If you don't believe me, query v$sqlfn_metadata.
This looks like a college homework question. You had better give it in full, and then perhaps someone can guide you to a solution.
|
|
|
|