-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateTime Functions.sql
More file actions
63 lines (51 loc) · 1.23 KB
/
DateTime Functions.sql
File metadata and controls
63 lines (51 loc) · 1.23 KB
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
61
62
-- use salesdb
-- SELECT * FROM orders;
-- SELECT
-- orderid,
-- creationtime,
-- YEAR(creationtime) year,
-- MONTH(creationtime) month,
-- DAY(creationtime) day
-- FROM orders;
-- SELECT
-- orderid,
-- creationtime,
-- YEAR(creationtime) AS year_dp,
-- MONTH(creationtime) AS month_dp,
-- DAY(creationtime) AS day_dp,
-- HOUR(creationtime) AS hour_dp,
-- QUARTER(creationtime) AS quarter_dp,
-- WEEK(creationtime) AS week_dp
-- FROM orders;
-- SELECT
-- orderid,
-- creationtime,
-- MONTHNAME(creationtime) AS mon,
-- WEEK(creationtime) AS weeks,
-- DAYNAME(creationtime) AS days,
-- YEAR(creationtime) AS years
-- FROM orders;
-- SELECT
-- orderid,
-- creationtime,
-- DATE(creationtime) AS daytrunc,
-- DATE_FORMAT(creationtime, '%Y-%m-%d %H:%i:00') AS mintrunc
-- FROM orders;
-- SELECT
-- orderid,
-- creationtime,
-- LAST_DAY(creationtime) AS eomonth,
-- MONTH(creationtime) AS startmon
-- FROM orders;
-- SELECT
-- YEAR(orderdate),
-- COUNT(*) no_orders
-- FROM orders
-- GROUP BY YEAR(orderdate);
-- SELECT
-- MONTHNAME(orderdate) AS order_date,
-- COUNT(*) no_orders
-- FROM orders
-- GROUP BY MONTHNAME(orderdate);
-- SELECT * FROM orders
-- WHERE MONTH(orderdate)=2