INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

MySQL query help to display 'missing' values when comparing All Clients' data to one Clients data

MySQL query help to display 'missing' values when comparing All Clients' data to one Clients data

MySQL query help to display 'missing' values when comparing All Clients' data to one Clients data

(OP)
My query is set to compare All Clients survey data (likert scale) to a specific Client's survey data.
My current query unions the data - no problem.
The problem begins when I'm comparing the scale value aka Response: The All clients query returns data for all or most of the values but the specific Clients data may only have values for some of the scale values.
The scale values I'm interested in are 1 - 5.

This is what I have currently:

Client Question Response NumOfResponses Client Question Response NumOfResponses
All Question1 1 10 Client150 Question1 1 2
All Question1 2 25 Client150 Question1 2 5
All Question1 3 40 Client150 Question1 4 13
All Question1 4 100 Client150 Question1 5 25
All Question1 5 210

This is what I want:

Client Question Response NumOfResponses Client Question Response NumOfResponses
All Question1 1 10 Client150 Question1 1 2
All Question1 2 25 Client150 Question1 2 5
All Question1 3 40 Client150 Question1 3 0
All Question1 4 100 Client150 Question1 4 13
All Question1 5 210 Client150 Question1 5 25

Because I need to display them in a report I'd like to include for Client150, Question1, Response 3 with zero(0) count but can't seem to figure out how to do that in my query.

Here's a generic short form of my query

set @Client = 'Client150';

SELECT
'All' as Client,
Question,
Response,
Count(Response) as NumOfResponses
from
SurveyData sd
INNER JOIN Clients c
on sd.ClientCode = c.ClientCode
WHERE c.Reported = 1
and sq.Response not in ('',0)
and (sd.SurveyDate >= DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -DAY(CURDATE())+1 DAY), INTERVAL -6 MONTH)
and sd.SurveyDate <= Last_day(DATE_ADD(CURDATE(),INTERVAL -1 MONTH)))
Group by Client, Question, Response
UNION
SELECT
Client,
Question,
Response,
Count(Response) as NumOfResponses
from
SurveyData sd
INNER JOIN Clients c
on sd.ClientCode = c.ClientCode
WHERE c.Reported = 1
and Client = @Client
and sq.Response not in ('',0)
and (sd.SurveyDate >= DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -DAY(CURDATE())+1 DAY), INTERVAL -6 MONTH)
and sd.SurveyDate <= Last_day(DATE_ADD(CURDATE(),INTERVAL -1 MONTH)))
Group by Client, Question, Response;


Thanks in advance

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close