Jump to content
The mkiv Supra Owners Club

SQL Heirachy Counts help


mikeyb10supra

Recommended Posts

Hey guys, im running some counts in SQL and want them to be run as a heirachy, ie if they fall into the first case ie pledger, then they wont appear in the next two case statements. Im pretty sure what I have done below correct and will it work as I have said. Be useful to get a second opinion

 

 

 

 

SELECT LEGACY_STATUS, count(distinct contact_number) FROM

 

(select contact_number,

CASE WHEN activity_value in ('PLE', 'PEC', 'RES', 'FWS') THEN 'LEG_PLEDGERS'

WHEN activity_value = 'INT' THEN 'LEG_INTENDERS'

WHEN activity_value in ('ENQ','BKLT','FWLT') THEN 'LEG_ENQUIRER' ELSE 'NO_LEGACY' END AS LEGACY_STATUS

FROM contact_categories

where activity = 'LEG')

 

GROUP BY LEGACY_STATUS;

Link to comment
Share on other sites

I've done something very similar at work, which unfortunately I am not back in until Sunday.

 

Basicly you have the same type of nested query, but the nested query returns either a 1 or 0 for the results and you just SUM the results in the top level query.

 

This link has something similar in it, once I'm back in work I can pass you what I have done.

 

Cheers,

 

Paul.

Link to comment
Share on other sites

I've done something very similar at work, which unfortunately I am not back in until Sunday.

 

Basicly you have the same type of nested query, but the nested query returns either a 1 or 0 for the results and you just SUM the results in the top level query.

 

This link has something similar in it, once I'm back in work I can pass you what I have done.

 

Cheers,

 

Paul.

 

 

Will that take out dupes though?? If condition 1 is satisfied and they have a pledger activity then its = 1

 

But if condition 2 is also satisfied and the same person picked up above also has an 'INT' value surely they will be counted again?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. You might also be interested in our Guidelines, Privacy Policy and Terms of Use.