Home » SQL & PL/SQL » SQL & PL/SQL » Need answer to this Query (Oracle 10G AS)
Need answer to this Query [message #437904] Wed, 06 January 2010 08:42 Go to next message
gurusuryas
Messages: 49
Registered: March 2009
Location: Chennai
Member


Table name: T1, it has only one column.

col1
------
c
b
a
b
b
b
b
d
s
a
a
t
s


Requirement:

I need the following output from the above base table by using SQL query.


col1 Cnt
----- -------
a 3
b 5
Others 5


Please help.

Thanks
Gurus








Re: Need answer to this Query [message #437906 is a reply to message #437904] Wed, 06 January 2010 08:45 Go to previous messageGo to next message
cookiemonster
Messages: 12320
Registered: September 2008
Location: Rainy Manchester
Senior Member
By my reckoning others should be 7 not 5.
You can do this easily using a combination of count, case and group by.
Re: Need answer to this Query [message #437913 is a reply to message #437904] Wed, 06 January 2010 09:04 Go to previous messageGo to next message
Michel Cadot
Messages: 63801
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
1/
lease read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.

2/
Also always post your Oracle version with 4 decimals.

3/
Post a workingTest case: create table and insert statements along with the result you want with these data.

4/
Quote:
I need the following output from the above base table by using SQL query.

Base on what? What is the rule? An ouput is not a question.

5/
This is a FAQ answered many times, please search BEFORE posting.

Regards
Michel
Re: Need answer to this Query [message #438106 is a reply to message #437906] Thu, 07 January 2010 02:56 Go to previous message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
cookiemonster wrote on Wed, 06 January 2010 15:45
By my reckoning others should be 7 not 5.
We can't be sure, since we have no actual question.
cookiemonster wrote on Wed, 06 January 2010 15:45
You can do this easily using a combination of count, case and group by.
Decode would be my choice. Good pointer though!


MHE
Previous Topic: how oracle executes sql statements
Next Topic: pl/sql
Goto Forum:
  


Current Time: Sun Sep 25 06:07:25 CDT 2016

Total time taken to generate the page: 0.13968 seconds