English 中文(简体)
不包括AVGQ功能中的记录? (由于另一个数字,在主要询问中使用WHERE
原标题:Exclude records in AVG SQL function? (can t use WHERE in main query because of another count)

我要问的是,什么是罚款?

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  

由于我的计算机辅助设备职能需要服务 ADSL

如何解决这一问题?

成就

最佳回答

Avg()总功能忽视了,如果服务是ADSL ,则你可以宣布无效。

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

您可尝试rel=“nofollow”>coalesce :

   COALESCE (AVG (case when service !=  ADSL 
             then timestampdiff(4, char(actualfinish - reportdate))/60.00) 
             else null
         end), 0) as efficiency
问题回答

Calculate AVG salary excluding min() and max() salaries in a table.

select round(avg(table.salary),2) from table
where table.salary NOT IN ((select min(salary) from table), (select max(salary) from table)) 




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签