试图合并项目并找到平均值

时间:2018-08-09 17:06:27

标签: sql average

我正在尝试像opods和dpods那样组合,并找到每种组合的平均final_nr。

select column_1, column_2, Column_3, final, cust_name
From big2
Where q_date > '2017-1-1'
and cust_name = 'XYZ, LLC'
and setup = 1

should look like 
Column_1  Column_2 Column_3  final  customer name 
    a         b       3       $50        XYZ
    a         c       2       $45        XYZ
    c         d       5       $55        XYZ

2 个答案:

答案 0 :(得分:0)

尝试以下查询-:

select Opod, Dpod, finlocked,avg(final_nr), cust_name
From analytics..ig_uly2
Where quote_date > '2017-1-1'
and cust_name = 'XYZ, LLC'
and setup = 1
group by Opod, Dpod, finlocked, cust_name

SQL Server

答案 1 :(得分:0)

只需使用avgin聚合函数 并在考虑两个客户名称时使用 select Opod, Dpod, finlocked, avg(final_nr) as avgfinal, cust_name From analytics..ig_uly2 Where quote_date > '2017-01-01' and cust_name in( 'XYZ', 'LLC') and setup = 1 group by Opod, Dpod, finlocked,cust_name 子句

SELECT ID, group_concat(Name) AS Names
FROM MyTable
WHERE Date IN ('08/06/15', '17/04/16', '23/08/13', '09/08/18')
GROUP BY ID;