Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old September 3rd, 2003, 02:41 PM
Karin Karin is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 7 Karin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation problem with decode and group by

I need to do a query that returns how many estudents are in each grade of a school, this is my query:

select decode(grade.order,11,count(axgs.cuser),null) "1º",decode(grade.iorder,12,count(axgs.cuser),null)"2º",decode(grade.iorder,13,count(axgs.cuser),null) "3º",decode(grado.iorder,14,count(axgs.cuser),null) "4º" from pro_grades grade,pro_students_x_grades_seccion axgs,pro_school schoolwhere school.cschool=559 and grade.cschool=school.cschool and axgs.cgrade=grade.cgrade group by grade.iorder;

This is the result:

1º 2º 3º 4º
---------- ---------- ---------- ---------- -




15
15
7
15


The result is what i want but i need the numbers to be in just one row, something like:



1º 2º 3º 4º
---------- ---------- ---------- ---------- -
15 15 7 15

Probably is easy but i can`t figure out how to do it,thanks fot the help!!

PD: The results in the first table are in diagonal

Reply With Quote
  #2  
Old September 3rd, 2003, 04:06 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 21 h 49 m 55 sec
Reputation Power: 19
woops misread, I think this should do what you want:

PHP Code:
 select sum(decode(grade.iorder,11,1,0)) "1º",
       
sum(decode(grade.iorder,12,1,0)) "2º",
       
sum(decode(grade.iorder,13,1,0)) "3º",
       
sum(decode(grado.iorder,14,1,0)) "4º" 
  
from pro_grades gradepro_students_x_grades_seccion axgspro_school school
 where school
.cschool=559 
   
and grade.cschool=school.cschool 
   
and axgs.cgrade=grade.cgrade


it builds a tally with the decode and then adds it up with the sum

Last edited by hedge : September 3rd, 2003 at 04:16 PM.

Reply With Quote
  #3  
Old September 3rd, 2003, 04:18 PM
Karin Karin is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 7 Karin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I can`t, if i do that i have this error ORA-00937: not a single-group group function

Reply With Quote
  #4  
Old September 3rd, 2003, 04:23 PM
Karin Karin is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 7 Karin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It works! Thanks a lot!

Reply With Quote
  #5  
Old September 3rd, 2003, 04:45 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 21 h 49 m 55 sec
Reputation Power: 19
good, BTW this probably should have been posted to the Oracle board

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > problem with decode and group by


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway