PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

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:
  #1  
Old June 23rd, 2002, 07:14 PM
BJC BJC is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Little Neck, New York
Posts: 6 BJC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Having trouble translating a MySQL query

I'm having trouble translating the following:

select sum(if(grad="1998",1,0)) as "1998",sum(if(grad="1999",1,0)) as "1999",sum(if(grad="2000",1,0)) as "2000", sum(if(grad="2001",1,0)) as "2001", sum(if(grad="2002",1,0)) as "2002",sum(if(grad="2003",1,0)) as "2003", sum(if(grad="2004",1,0)) as "2004",sum(if(grad="2005",1,0)) as "2005" from students;

The reason for this instead of separate select count(*) from students where grad="whatever" is because it's significantly faster - goes through the whole table once instead of 8 times. Postgres seems to also suffer from speed degradion from select count(*)'s. (this needs to be faster because this loads from PHP on a webpage, and there is a difference in loading time. I can't use MySQL because, well, it's being phased out for 'compliance' adaptation. I can't say anything to that.)

Is there something I should look into? I couldn't find the if() function anywhere in the Postgres documentation.

Thanks in advance.

Reply With Quote
  #2  
Old June 23rd, 2002, 08:59 PM
BJC BJC is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Little Neck, New York
Posts: 6 BJC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I found a solution, but just in case anyone here might have an enlightening comment...

select grad,count(*) from students group by students.grad;

This not only really speeds Postgres up, it also speeds up on MySQL.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Having trouble translating a MySQL query

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap