You are viewing cyberlizard

 

The CyberLizard - SQL to generate frequency counts

About SQL to generate frequency counts

Previous Entry SQL to generate frequency counts May. 13th, 2004 @ 11:17 pm Next Entry

Question: Say you had the following tables:

Group
idname
Item
idgroup_idstatus

How do you generate frequency counts grouped by status, in such a way that the frequency counts are columns of a row with the group_id, given three status codes (0 == ok, 1 == fail, 2 == pending)? That is, how do you get to the following table:

Frequencies
group_idok_countfail_countpending_count

The following SQL should do the trick:

SELECT g.Group, ok_count, fail_count, pending_count
FROM Group g
LEFT JOIN
(
   SELECT group_id, COUNT(status) as ok_count
   FROM Item
   WHERE status = 0
   GROUP BY status, group_id
) ok
ON g.group_id = ok.group_id
LEFT JOIN
(
   SELECT group_id, COUNT(status) as fail_count
FROM Item WHERE status = 1 GROUP BY status, group_id ) fail ON g.group_id = fail.group_id LEFT JOIN ( SELECT group_id, COUNT(status) as pending_count FROM Item WHERE status = 2 GROUP BY status, group_id ) pending ON g.group_id = pending.group_id

Current Mood: accomplished
Leave a comment
From:(Anonymous)
Date:January 21st, 2008 11:25 am (UTC)

My blog about health and wealth

(Link)
Why you should buy viaga info?
First of all, if you buy us gneric viagra you get quality service and great discounts!
Why would you need herba viagra?
Viagra in the first place make a uverenost, most of the problems are solved in the privacy of using our products. We will help you learn infinite possibilities in the intimate lives.
Why do you have to use our shop?
You pay only real value of the goods, without deductions resellers percent! Ordering viagra for oman us, you get free delivery and discounts on other products.
On our site you can order viaga online. The lowest price. Large discounts. Full anonymity. Free shipping.
More info about vigra online you can be found on our website http://buy-viagra-online-pharmacy-in-canada.info/buy-cheap-viagra-online-now/free-online-viagra.php
From:karachhleche
Date:June 8th, 2009 03:36 am (UTC)
(Link)
Could not find where you can buy ED drugs. I found one online store at normal prices. Delivered by mail and at normal prices. Continuing not take pills, but sometimes. For example when I come after the change, and the girlfriend wants to meet) But there are ways to increase sexual potency?
From:(Anonymous)
Date:January 10th, 2011 02:40 pm (UTC)

carmen electra naked

(Link)
Count Leo Nikolaevich Tolstoy We should show life neither as it is or as it it ought to be, but only as we see it in our dreams. [url=http://paris-hilton-sex-tape.com]paris hilton sex tape[/url] katie price son harvey elderly female nudes [url=http://paris-hilton-sex-tape.com/2010/09/02/katie-price-nude/]katie price nude[/url] lipids injure instill katie price nude (http://paris-hilton-sex-tape.com/2010/09/02/katie-price-nude/) The Bible Reprove not a scorner, lest he hate thee: rebuke a wise man, and he will love thee. thermometers stanza westin torrie wilson swimsuit peter andre naked katie price nude (http://paris-hilton-sex-tape.com/2010/09/02/katie-price-nude/) Unknown There is no such thing as an absolute truth — that is absolutely true. http://forum.lycee-tam.blueheberg.net//jointhe200/forums//member.php?u=27293 steal rifle badly
From:(Anonymous)
Date:February 12th, 2011 10:41 pm (UTC)

iphone 3g unlock eunlockiphone3g

(Link)
iphone 3g unlock (http://e-unlockiphone3g.com) jailbreak iphone 3g how to unlock iphone 3g iphone 3g jailbreak iphone 3g unlocker unlock iphone 3g ?
(Leave a comment)
Top of Page Powered by LiveJournal.com