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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:37:18+00:00 2026-06-04T00:37:18+00:00

my SQL query which works fine is select case month(timestamp_iso(STATUSDATE)) when 1 then ‘January’

  • 0

my SQL query which works fine is

select case month(timestamp_iso(STATUSDATE))
        when 1 then 'January'
        when 2 then 'February'
        when 3 then 'March'
        when 4 then 'April'
        when 5 then 'May'
        when 6 then 'Jun'
        when 7 then 'July'
        when 8 then 'August'
        when 9 then 'September' 
        when 10 then 'October'
        when 11 then 'November'
        when 12 then 'December'
    end as Month, 

    count (case when service='ADSL' then 1 end) as  ADSL,
  AVG (timestampdiff(
  4, 
  char(actualfinish - reportdate))/60.00) as efficiecny



from INCIDENT
where   year(STATUSDATE) = year(current_timestamp) 
group by month(timestamp_iso(STATUSDATE))

I want to get for each month number of services with ADSL (it is done through the first COUNT)
and average time difference in hours for the records which do not have service ADSL. So I must exclude in the AVG function all records with service ADSL but I can not put it in where clause

 where   year(STATUSDATE) = year(current_timestamp) and service!='ADSL' 

because my COUNT function needs to have service=’ADSL’

How to solve this?

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-04T00:37:21+00:00Added an answer on June 4, 2026 at 12:37 am

    As Avg() aggregate function ignores nulls, you can set expression to null if service is ‘ADSL’. Avg() will then ignore those records.

       AVG (case when service != 'ADSL'
                 then timestampdiff(4, char(actualfinish - reportdate))/60.00) 
                 else null
             end) as efficiency
    

    You could try with coalesce:

       COALESCE (AVG (case when service != 'ADSL'
                 then timestampdiff(4, char(actualfinish - reportdate))/60.00) 
                 else null
             end), 0) as efficiency
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL query with a left join which works fine: SELECT book.*
using php, i have a sql query which works fine, dateentry only has the
I want to port this SQL query, which works just fine on SQL Server,
I have the following which works in SQL Query Analyzer . select oh.* from
In SQL SERVER 2005 This query works fine : Select * from sys.procedures where
I have written a MDX query which works fine in SQL Server Management Studio.
I'm having an issue trying to get my SQL query which works fine in
SQL query which select the record from three tables and there is no relation
I have the following HQL query which works fine, however it returns a list
I am using the below query to run an sql statement. It works fine.

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.