我正在尝试像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
答案 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)
只需使用avg
和in
聚合函数
并在考虑两个客户名称时使用 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;