-
Notifications
You must be signed in to change notification settings - Fork 2
/
with_exprs_d18_group_by_19_cols.sql
60 lines (56 loc) · 1.26 KB
/
with_exprs_d18_group_by_19_cols.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
select
count(*) as count_star,
sum(a.d18) as sum_d18,
--round(avg(a.d18)) as round_avg_d18,
cast(avg(a.d18) as bigint) as round_avg_d18,
--trunc(avg(a.d18)) as trunc_avg_d18,
cast(avg(a.d18) as bigint) as trunc_avg_d18,
--sum(case when a.d18 = 0 then 100 else round(a.d18/12) end) as case_in_sum_d18,
cast(sum(case when a.d18 = 0 then 100 else round(a.d18/12) end) as bigint) as case_in_sum_d18,
--coalesce(sum(case when a.d18 = 0 then 100 else round(a.d18/12) end), 0) as case_in_sum_d18
cast(coalesce(sum(case when a.d18 = 0 then 100 else round(a.d18/12) end), 0) as bigint) as case_in_sum_d18_0
from
alltypes_with_nulls_v a
left outer join alltypes_with_nulls_v b on (a.c_integer = b.c_integer)
left outer join alltypes_with_nulls_v c on (b.c_integer = c.c_integer)
group by
a.c_varchar
,b.c_varchar
,c.c_varchar
,a.c_integer
,b.c_integer
,c.c_integer
,a.d9
,b.d9
,c.d9
,a.d18
,b.d18
,c.d18
,a.d28
,b.d28
,c.d28
,a.d38
,b.d38
,c.d38
,a.c_date
order by
a.c_varchar
,b.c_varchar
,c.c_varchar
,a.c_integer
,b.c_integer
,c.c_integer
,a.d9
,b.d9
,c.d9
,a.d18
,b.d18
,c.d18
,a.d28
,b.d28
,c.d28
,a.d38
,b.d38
,c.d38
,a.c_date
;