LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 03-13-2007, 06:38 PM   #1
OlRoy
Member
 
Registered: Dec 2002
Posts: 304

Rep: Reputation: 86
How would I make this SQL query


I'm new to SQL and have written a few SQL statements, but this one has me stumped. I want to take the sum of all rows that have either a status of 11 of 12 and divide that by the total number of rows with a status of 13. I can't use a WHERE status = '11' or '12' in the SELECT part so I don't even know where to start.
 
Old 03-13-2007, 06:58 PM   #2
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Will this get you started?
Code:
SELECT * FROM table WHERE status=11 OR status=12;
 
Old 03-13-2007, 07:16 PM   #3
OlRoy
Member
 
Registered: Dec 2002
Posts: 304

Original Poster
Rep: Reputation: 86
No, I don't see where I can go from that. This syntax here is wrong, but this is what i'd like to be able to do written in pseudo code.

SELECT COUNT(WHERE status = '11' OR '12') / COUNT(WHERE status = '13');
 
Old 03-14-2007, 03:51 PM   #4
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Try something like this:
Code:
SELECT @a:=COUNT(status) WHERE status=11 OR status=12
UNION SELECT @b:=COUNT(status) WHERE status=13
UNION SELECT @a/@b ;
Use it as a subquery and retrieve only the last line.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in SQL Query.. gobi_dgm Linux - Software 1 02-03-2007 10:41 AM
SQL query question Kamikazee Programming 2 10-31-2006 11:27 AM
Query SQL error gabsik Linux - Software 37 07-22-2006 03:34 AM
SQL query help pls. vickr1z Programming 8 10-19-2004 12:25 AM
SQL Query question oulevon Programming 7 01-16-2004 02:50 AM


All times are GMT -5. The time now is 06:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration