-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7-4.sql
More file actions
36 lines (34 loc) · 756 Bytes
/
7-4.sql
File metadata and controls
36 lines (34 loc) · 756 Bytes
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
-- find difference between two dates
select
orderid,
productcategory,
productsubcategory,
orderdate,
projectcompletedate,
datediff(projectcompletedate, orderdate) duration
from sales_all_years
-- get some stats by month
select
productcategory,
productsubcategory,
year(orderdate) y,
month(orderdate) m,
avg(datediff(projectcompletedate, orderdate)) duration
from sales_all_years
group by
productcategory,
productsubcategory,
year(orderdate),
month(orderdate)
order by
3,4
-- find the last day of the month
select distinct
date_sub(
to_date(
concat(cast(year(orderdate) as string),"-",cast(month(orderdate)+1 as string),"-01")
)
,1 ),
orderdate
from sales_all_years
limit 100;