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 8500861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:03:16+00:00 2026-06-11T01:03:16+00:00

Hi guys I’m having problems to make a query in sql server. I have

  • 0

Hi guys I’m having problems to make a query in sql server.

I have 3 tables: testcases, executions and execution_bugs:

testcases

id | name
-------------
1  | Login
2  | Logout

executions

id | testcase_id
-----------------
1  | 1
2  | 2
3  | 1

execution_bugs

execution_id | bug_id
----------------------
1            | B-1
3            | B-2

And I need to know how many testcases are defined, how many of them have been executed, how many testcases have bugs and how many do not.

I was looking for a query that would give me this kind of result:

testcases_n | executed | with_bugs | without_bugs | bugs_amount
---------------------------------------------------------------
2           | 2        | 1         | 1            | 2

Is this possible given the table structure?

Thanks!

  • 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-11T01:03:17+00:00Added an answer on June 11, 2026 at 1:03 am

    You mean something like this:

    declare @testcases as table ( id int, name varchar(16) )
    insert into @testcases ( id, name ) values
      ( 1, 'login' ), ( 2, 'Logout' )
    
    declare @executions as table ( id int, testcase_id int )
    insert into @executions ( id, testcase_id ) values
      ( 1, 1 ), ( 2, 2 ), ( 3, 1 )
    
    declare @execution_bugs as table ( execution_id int, bug_id varchar(16) )
    insert into @execution_bugs ( execution_id, bug_id ) values
      ( 1, 'B-1' ), ( 3, 'B-2' )
    
    select
      ( select count(42) from @testcases ) as testcases_n,
      ( select count(distinct testcase_id) from @executions ) as executed,
      ( select count(distinct e.testcase_id) from @executions as e inner join @execution_bugs as eb on eb.execution_id = e.id ) as with_bugs,
      ( select count(42) from @testcases ) - ( select count(distinct e.testcase_id) from @executions as e inner join @execution_bugs as eb on eb.execution_id = e.id ) as without_bugs,
      ( select count(42) from @execution_bugs ) as bugs_amount
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys I have 4 tables in my DB as follows Functions {id, name Admin_Users
Guys I've 3 tables as follows: Project {id, name, owner, ....} ProjectMilestones {id, project_id,
Guys, I am using SQL Server 2000 and executing the sp_columns stored procedure to
guys i have a xml file which is like this: <Point TestFlag=0 id=1 name=Conversation
Guys can you suggest me any software who have some similarities with Microsoft's SQL
Guys back to being stuck with my sql layout on my tables, I just
Guys i m having a table in which i have gender and date columns
Guys i was given a project (server-side c# sn generator) for whom i have
Guys I have an activity which has a home button, when the button is
guys. I have a strange problem. I try to write unit-tests to web-app. I

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.