~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
drop table if exists t1;
2
CREATE TABLE t1 (
3
visitor_id int(10) unsigned DEFAULT '0' NOT NULL,
4
group_id int(10) unsigned DEFAULT '0' NOT NULL,
5
hits int(10) unsigned DEFAULT '0' NOT NULL,
6
sessions int(10) unsigned DEFAULT '0' NOT NULL,
7
ts timestamp,
8
PRIMARY KEY (visitor_id,group_id)
9
)/*! engine=MyISAM */;
10
INSERT INTO t1 VALUES (465931136,7,2,2,20000318160952);
11
INSERT INTO t1 VALUES (173865424,2,2,2,20000318233615);
12
INSERT INTO t1 VALUES (173865424,8,2,2,20000318233615);
13
INSERT INTO t1 VALUES (173865424,39,2,2,20000318233615);
14
INSERT INTO t1 VALUES (173865424,7,2,2,20000318233615);
15
INSERT INTO t1 VALUES (173865424,3,2,2,20000318233615);
16
INSERT INTO t1 VALUES (173865424,6,2,2,20000318233615);
17
INSERT INTO t1 VALUES (173865424,60,2,2,20000318233615);
18
INSERT INTO t1 VALUES (173865424,1502,2,2,20000318233615);
19
INSERT INTO t1 VALUES (48985536,2,2,2,20000319013932);
20
INSERT INTO t1 VALUES (48985536,8,2,2,20000319013932);
21
INSERT INTO t1 VALUES (48985536,39,2,2,20000319013932);
22
INSERT INTO t1 VALUES (48985536,7,2,2,20000319013932);
23
INSERT INTO t1 VALUES (465931136,3,2,2,20000318160951);
24
INSERT INTO t1 VALUES (465931136,119,1,1,20000318160953);
25
INSERT INTO t1 VALUES (465931136,2,1,1,20000318160950);
26
INSERT INTO t1 VALUES (465931136,8,1,1,20000318160950);
27
INSERT INTO t1 VALUES (465931136,39,1,1,20000318160950);
28
INSERT INTO t1 VALUES (1092858576,14,1,1,20000319013445);
29
INSERT INTO t1 VALUES (357917728,3,2,2,20000319145026);
30
INSERT INTO t1 VALUES (357917728,7,2,2,20000319145027);
31
select visitor_id,max(ts) as mts from t1 group by visitor_id
32
having mts < DATE_SUB(NOW(),INTERVAL 3 MONTH);
33
visitor_id	mts
34
48985536	2000-03-19 01:39:32
35
173865424	2000-03-18 23:36:15
36
357917728	2000-03-19 14:50:27
37
465931136	2000-03-18 16:09:53
38
1092858576	2000-03-19 01:34:45
39
select visitor_id,max(ts) as mts from t1 group by visitor_id
40
having DATE_ADD(mts,INTERVAL 3 MONTH) < NOW();
41
visitor_id	mts
42
48985536	2000-03-19 01:39:32
43
173865424	2000-03-18 23:36:15
44
357917728	2000-03-19 14:50:27
45
465931136	2000-03-18 16:09:53
46
1092858576	2000-03-19 01:34:45
47
drop table t1;
48
set sql_mode='traditional';
49
create table t1 (d date);
50
insert into t1 (d) select date_sub('2000-01-01', INTERVAL 2001 YEAR);
51
ERROR 22008: Datetime function: datetime field overflow
52
insert into t1 (d) select date_add('2000-01-01',interval 8000 year);
53
ERROR 22008: Datetime function: datetime field overflow
54
insert into t1 values (date_add(NULL, INTERVAL 1 DAY));
55
insert into t1 values (date_add('2000-01-04', INTERVAL NULL DAY));
56
set sql_mode='';
57
insert into t1 (d) select date_sub('2000-01-01', INTERVAL 2001 YEAR);
58
Warnings:
59
Warning	1441	Datetime function: datetime field overflow
60
insert into t1 (d) select date_add('2000-01-01',interval 8000 year);
61
Warnings:
62
Warning	1441	Datetime function: datetime field overflow
63
insert into t1 values (date_add(NULL, INTERVAL 1 DAY));
64
insert into t1 values (date_add('2000-01-04', INTERVAL NULL DAY));
65
select * from t1;
66
d
67
NULL
68
NULL
69
NULL
70
NULL
71
NULL
72
NULL
73
drop table t1;
74
End of 4.1 tests
75
SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 DAY;
76
CAST('2006-09-26' AS DATE) + INTERVAL 1 DAY
77
2006-09-27
78
SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 MONTH;
79
CAST('2006-09-26' AS DATE) + INTERVAL 1 MONTH
80
2006-10-26
81
SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 YEAR;
82
CAST('2006-09-26' AS DATE) + INTERVAL 1 YEAR
83
2007-09-26
84
SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 WEEK;
85
CAST('2006-09-26' AS DATE) + INTERVAL 1 WEEK
86
2006-10-03
87
create table t1 (a int, b varchar(10));
88
insert into t1 values (1, '2001-01-01'),(2, '2002-02-02');
89
select '2007-01-01' + interval a day from t1;
90
'2007-01-01' + interval a day
91
2007-01-02
92
2007-01-03
93
select b + interval a day from t1;
94
b + interval a day
95
2001-01-02
96
2002-02-04
97
drop table t1;
98
End of 5.0 tests