LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   How would I make this SQL query (http://www.linuxquestions.org/questions/linux-server-73/how-would-i-make-this-sql-query-537205/)

OlRoy 03-13-2007 05:38 PM

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.

spirit receiver 03-13-2007 05:58 PM

Will this get you started?
Code:

SELECT * FROM table WHERE status=11 OR status=12;

OlRoy 03-13-2007 06:16 PM

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');

spirit receiver 03-14-2007 02:51 PM

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.


All times are GMT -5. The time now is 08:59 PM.