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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:50:44+00:00 2026-05-23T15:50:44+00:00

select problemrecordedbytitle,problemstatus , count(problemstatus) from problemtable where problemrecordedccyy >=’2011′ and problemrecordedbytitle like ‘LPM%’ group

  • 0
select problemrecordedbytitle,problemstatus ,
       count(problemstatus) from problemtable 
where problemrecordedccyy >='2011'
and problemrecordedbytitle like 'LPM%'
group by problemrecordedbytitle, problemstatus
order by problemrecordedbytitle asc

LPM-AMS-EDW Open    1
LPM-AMS-EDW WIP     1
LPM-AMS-EOM Closed  4

this sql provides me with nice summary of statuses. however i got a new requirement today.

i want to sum of all ie count(problemstatus) and count(problemstatus<>closed) in summary.
it should be like

LPM-AMS-EDW    NotClosed    2
LPM-AMS-EDW    Total        6

I am not sure how i can do it in TSQL

  • 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-05-23T15:50:44+00:00Added an answer on May 23, 2026 at 3:50 pm

    You really should be careful not to group on fields with different values.
    This will give you the result you are looking for as described.

    ;WITH a as(
    SELECT problemrecordedbytitle,problemstatus from problemtable  
    WHERE problemrecordedccyy >='2011' 
    and problemrecordedbytitle like 'LPM%' 
    )
    SELECT problemrecordedbytitle, 'NotClosed', COUNT(*) FROM a WHERE problemstatus <> 'Closed' 
    GROUP BY problemrecordedbytitle
    UNION ALL
    SELECT MIN(problemrecordedbytitle), 'Total', COUNT(*) FROM a
    

    I would rewrite it to this to prevent those group problems:

    declare @problemtable table (problemrecordedbytitle varchar(20), problemstatus varchar(10))
    
    INSERT @problemtable values('LPM-AMS-EDW', 'Open')
    INSERT @problemtable values('LPM-AMS-EDW','WIP')
    INSERT @problemtable values('LPM-AMS-EOM','Closed')
    INSERT @problemtable values('LPM-AMS-EOM','Closed')
    INSERT @problemtable values('LPM-AMS-EOM','Closed')
    INSERT @problemtable values('LPM-AMS-EOM','Closed')
    
    ;WITH a as(
    SELECT left(problemrecordedbytitle, 3) problemrecordedbytitle,problemstatus 
    FROM @problemtable -- replace this tablename for your script 
    -- You need these lines for your script
    -- WHERE problemrecordedccyy >='2011' 
    -- and problemrecordedbytitle like 'LPM%' 
    )
    SELECT problemrecordedbytitle, 'NotClosed' [status], COUNT(*) count FROM a WHERE problemstatus <> 'Closed' 
    GROUP BY problemrecordedbytitle
    UNION ALL
    SELECT MIN(problemrecordedbytitle), 'Total', COUNT(*) FROM a
    

    Result:

    problemrecordedbytitle status    count
    ---------------------- --------- -----------
    LPM                    NotClosed 2
    LPM                    Total     6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT `name` , COUNT(*) AS `count` FROM `t1`, `t2` WHERE `t2`.`id` = `t1`.`id` GROUP
SELECT NR_DZIALU, COUNT (NR_DZIALU) AS LICZ_PRAC_DZIALU FROM PRACOWNICY GROUP BY NR_DZIALU HAVING NR_DZIALU =
select NV.PHG From Nhanvien NV Group by NV.phg Having count(nv.Manv) >= all (select count(NV.MANV
select p.Id, sum(inc.Quantity) from Products p join Incomes inc group by p.Id order by
select count(category) from list where category like 'action' above is a query i want
SELECT P.pID FROM Department D, Professor P WHERE D.dID = P.dID ORDER count(pID); Mysql,
SELECT User, COUNT(User) as count FROM Tests GROUP by User; This works. However, if
SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY hrl.Frn) as Row, hrl.unq, hrl.LcnsId, hc.Business,hc.Name,hc.Phone,
Select user_name [User Name], first_name [First Name], last_name [Last Name] From tab_user ORDER BY
select id from dm_unit where aa like '%'||?||'%'

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.