SQL Basics

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



Go Back   Tutorialized ForumsDatabasesSQL Basics

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 Tutorialized Forums Sponsor:
  #1  
Old November 13th, 2012, 08:12 PM
witsendestate witsendestate is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 witsendestate User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 14 sec
Reputation Power: 0
Joining of two queries

Team,

I am trying to write a query to display the following:

Pickerid, Pickername, Premiumcount, Rubbishcount

Each Pickerid has multiple entries in the table. ie

Pickerid Pickername Grade
1 test1 PR
1 test1 AP
1 test1 CA
1 test1 AM
1 test1 AA

and so on....

I am trying to get a grouped count which uses this logic.

Each Pickerid I need to count the number of "Grade" records equal to PR and AP. This we shall call Premiumcount, I also want to group the other "Grades" which are equal to "CA", "AM" & "AA" which we shall call Rubbishcount

These records all reside on the same table.

This is the result for the above I'm after.

Pickerid PickerName PremiumCount RubbishCount
1 test1 2 3

Each of my queries work individually but when I join them / union them I get no result.

I appreciate your help.

SELECT Q1.Pickerid, Q1.Pickername, PremiumCount, RubbishCount
FROM (SELECT Pickerid, Pickername, Count(*) AS PremiumCount FROM mergeddatabase WHERE (((Currentdate) between [Enter First Date Required:] and [Enter Last Date Required:]) and (grade = "PR" or grade = "AP" )) GROUP BY grade, PICKERID, PICKERNAME) AS Q1, (SELECT Pickerid, Pickername, Count(*) AS RubbishCount FROM mergeddatabase WHERE (((Currentdate) between [Enter First Date Required:] and [Enter Last Date Required:]) and (grade = "CA" or grade = "AM" or grade = "AA" )) GROUP BY grade, PICKERID, PICKERNAME) AS Q2
WHERE Q1.Pickerid = Q2.Pickerid;

Sorry for the formatting.. looks fine on my editor.

Regards
Mark

Last edited by witsendestate : November 13th, 2012 at 08:29 PM.

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > Joining of two queries


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 - 2014, Jelsoft Enterprises Ltd.

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