type_date.test
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:2k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. #
  2. # test of problem with date fields
  3. #
  4. create table t1 (a char(16), b date, c datetime);
  5. insert into t1 SET a='test 2000-01-01', b='2000-01-01', c='2000-01-01';
  6. select * from t1 where c = '2000-01-01';
  7. select * from t1 where b = '2000-01-01';
  8. drop table t1;
  9. #
  10. # problem with date conversions
  11. #
  12. drop table if exists t1,t2;
  13. CREATE TABLE t1 (name char(6),cdate date);
  14. INSERT INTO t1 VALUES ('name1','1998-01-01');
  15. INSERT INTO t1 VALUES ('name2','1998-01-01');
  16. INSERT INTO t1 VALUES ('name1','1998-01-02');
  17. INSERT INTO t1 VALUES ('name2','1998-01-02');
  18. CREATE TABLE t2 (cdate date, note char(6));
  19. INSERT INTO t2 VALUES ('1998-01-01','note01');
  20. INSERT INTO t2 VALUES ('1998-01-02','note02');
  21. select name,t1.cdate,note from t1,t2 where t1.cdate=t2.cdate and t1.cdate='1998-01-01';
  22. drop table t1,t2;
  23. #
  24. # Date and BETWEEN
  25. #
  26. CREATE TABLE t1 ( datum DATE );
  27. INSERT INTO t1 VALUES ( "2000-1-1" );
  28. INSERT INTO t1 VALUES ( "2000-1-2" );
  29. INSERT INTO t1 VALUES ( "2000-1-3" );
  30. INSERT INTO t1 VALUES ( "2000-1-4" );
  31. INSERT INTO t1 VALUES ( "2000-1-5" );
  32. SELECT * FROM t1 WHERE datum BETWEEN "2000-1-2" AND "2000-1-4";
  33. DROP TABLE t1;
  34. #
  35. # test of max(date) and having
  36. #
  37. CREATE TABLE t1 (
  38.   user_id char(10),
  39.   summa int(11),
  40.   rdate date
  41. );
  42. INSERT INTO t1 VALUES ('aaa',100,'1998-01-01');
  43. INSERT INTO t1 VALUES ('aaa',200,'1998-01-03');
  44. INSERT INTO t1 VALUES ('bbb',50,'1998-01-02');
  45. INSERT INTO t1 VALUES ('bbb',200,'1998-01-04');
  46. select max(rdate) as s from t1 where rdate < '1998-01-03' having s> "1998-01-01";
  47. select max(rdate) as s from t1 having s="1998-01-04";
  48. select max(rdate+0) as s from t1 having s="19980104";
  49. drop table t1;
  50. #
  51. # Test of date and not null
  52. #
  53. create table t1 (date date);  
  54. insert into t1 values ("2000-08-10"),("2000-08-11");
  55. select date_add(date,INTERVAL 1 DAY),date_add(date,INTERVAL 1 SECOND) from t1;
  56. drop table t1;