Home » SQL & PL/SQL » SQL & PL/SQL » Include row with out group by (Oracle 10g)
Include row with out group by [message #625292] Sat, 04 October 2014 02:48 Go to next message
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 Go to previous messageGo to next message
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 #625330 is a reply to message #625296] Mon, 06 October 2014 02:54 Go to previous messageGo to next message
sandeep_orafaq
Messages: 88
Registered: September 2014
Member
You can use anlytical functions.
Re: Include row with out group by [message #625332 is a reply to message #625330] Mon, 06 October 2014 03:04 Go to previous messageGo to next message
Michel Cadot
Messages: 68644
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You can but this is not the proper way.

Re: Include row with out group by [message #625333 is a reply to message #625292] Mon, 06 October 2014 03:06 Go to previous messageGo to next message
John Watson
Messages: 8930
Registered: January 2010
Location: Global Village
Senior Member
ind!@2020 wrote on Sat, 04 October 2014 08:48
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;

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.
Re: Include row with out group by [message #625335 is a reply to message #625333] Mon, 06 October 2014 03:41 Go to previous message
Michel Cadot
Messages: 68644
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Interesting view I didn't know, as well as its associated one V$SQLFN_ARG_METADATA.

Previous Topic: Question on LONG datatype
Next Topic: Strange Error 04021 timeout occurred while waiting to lock object <DIRECTORY>
Goto Forum:
  


Current Time: Wed Apr 24 02:34:16 CDT 2024