Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9273667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:10:05+00:00 2026-06-18T16:10:05+00:00

I’ve read close to a dozen similar issues on this site, but I don’t

  • 0

I’ve read close to a dozen similar issues on this site, but I don’t think my specific case was covered anywhere. I’m not a dba, this is just a side-project I was voluntold for because I knew more SQL than anyone else here, so I won’t take it personally if somebody tells me this query is a disaster. 🙂

This is my query:

SELECT COUNT(a.issue_type_id) as DistinctIssues, b.issue_type_name, c.subissue_type_name, null AS DistinctTickets
FROM [somedb].[dbo].[wh_task] AS a
INNER JOIN [somedb].[dbo].[wh_issue_type] AS b ON a.issue_type_id = b.issue_type_id
INNER JOIN [somedb].[dbo].[wh_subissue_type] AS c ON a.subissue_type_id = c.subissue_type_id
WHERE a.[create_time] between '11/01/12' AND '01/31/13'
AND a.[account_id] = 123456
AND a.[account_contact_id] is not null
GROUP BY b.issue_type_name, c.subissue_type_name  
UNION
SELECT null as DistinctIssues, b.issue_type_name, c.subissue_type_name, COUNT(a.issue_type_id) as DistinctTickets
FROM [somedb].[dbo].[wh_task] AS a
INNER JOIN [somedb].[dbo].[wh_issue_type] AS b ON a.issue_type_id = b.issue_type_id
INNER JOIN [somedb].[dbo].[wh_subissue_type] AS c ON a.subissue_type_id = c.subissue_type_id
WHERE a.[create_time] between '11/01/12' AND '01/31/13'
AND a.[account_id] = 123456
GROUP BY b.issue_type_name, c.subissue_type_name  

And the results look like this.

DistinctIssues  issue_type_name   subissue_type_name   DistinctTickets
NULL            Storage           EMC                  45
NULL            Storage           HP                   2
NULL            Symantec          Anti Virus           1
NULL            Symantec          Backup Exec          4
NULL            Virtualization    Environmental        1
NULL            Virtualization    Network              5
1               Microsoft         Server 2003          NULL
1               Microsoft         Windows 7            NULL
1               Network           Performance          NULL
1               Virtualization    Environmental        NULL
2               Exchange          Database             NULL

I bet you can guess what I’m trying to do from here.
I’m grouping by the two issue types, and I want the count of all tickets, as well as the count of a subset of those tickets. My database is a MS SQL server (2008, I believe). I only have access to views, for what that’s worth.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:10:06+00:00Added an answer on June 18, 2026 at 4:10 pm

    Both queries join the same tables on the same criteria, group the results on the same criteria and even count the same column. The only difference appears to be that one of the queries is using an additional condition in the WHERE clause.

    In that case, you can combine them into a single query, using conditional aggregation for the value returned by the query with the additional condition (DistinctIssues):

    SELECT
      COUNT(CASE WHEN a.[account_contact_id] is not null THEN a.issue_type_id END) as DistinctIssues,
      b.issue_type_name,
      c.subissue_type_name,
      COUNT(a.issue_type_id) as DistinctTickets
    FROM [somedb].[dbo].[wh_task] AS a
    INNER JOIN [somedb].[dbo].[wh_issue_type] AS b
      ON a.issue_type_id = b.issue_type_id
    INNER JOIN [somedb].[dbo].[wh_subissue_type] AS c
      ON a.subissue_type_id = c.subissue_type_id
    WHERE a.[create_time] between '11/01/12' AND '01/31/13'
      AND a.[account_id] = 123456
    GROUP BY b.issue_type_name, c.subissue_type_name
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm interested in microtypography issues on the web. I want a tool to fix:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.