Example queries for types and literals of instants and intervals:

1. List the information on those born on Jan. 1, 1970. 'test for DATE'

select *
from employee
where birthdate=date'01/01/1970';

2. List the information on those whose project time is 12:00:30 pm. 'TIME'

select *
from employee
where project_time=time'12:00:30 pm';

3. List the information on those  who checked in at 8:20:20 am on Feb. 1, 1997. 'TIMESTAMP'

select *
from employee
where checkin_time=timestamp'02/01/1997 8:20:20 am';

4. What's the interval between Feb. 5 and 15, 1970? 'INTERVAL DAY'

select date'02/15/1970'-date'02/05/1970'
from employee;

5. What's the interval between 12:00:30 pm and 11:00:30 am? 'INTERVAL SECOND'    

select time'12:00:30 pm'-time'11:00:30 am'
from employee;
   
6. What's the interval between 8:20:20 am and 8:10:10 am on Feb. 1, 1997? 'INTERVAL SECOND'

select timestamp'02/01/1997 8:20:20 am'-timestamp'02/01/1997 8:10:10 am'
from employee;

Example queries for predicates of instants and intervals:

7. List the information on those born on April 20, 1970. 'd1=d2'

select *
from employee
where birthdate=date'04/20/1971';

8. List the information on those born before Feb. 5, 1970. 'd1<d2'

select *
from employee
where birthdate < date'02/05/1970';

9. List the information on those not born on Jan. 1, 1970. 'd1<>d2'

select *
from employee
where not birthdate <> date'01/01/1970';

10. List the information on those born on Jan. 1, 1970. 'd1 BETWEEN d2 AND d3'

select *
from employee
where not birthdate not between date'01/01/1970' and date'01/01/1970';

11. List the information on those born on Jan. 1, 1970.  'd1 BETWEEN d2 AND d3'

select *
from employee
where birthdate between date'01/01/1970' and date'01/01/1970';

12. List the information on those 10 days older than those born on Feb. 5, 1970. 'i1=i2'

select *
from employee
where birthdate-date'02/05/1970'=10;

13. List the information on those less than 20 days older (but not younger or same age)than those born on Feb. 5, 1970. 'i1<i2'

select *
from employee
where birthdate-date'02/05/1970' < 20
  and birthdate-date'02/05/1970' > 0;

14. List the information on those not ten days younger than those born on Feb. 5, 1970. 'i1<>i2'

select *
from employee
where birthdate-date'02/05/1970' <> 10;

15. List the information on those born 10 to 40 days later than those born on Jan. 1, 1970. 'i1 BETWEEN i2 AND j3' 

select *
from employee
where birthdate-date'01/01/1970' between 10 and 40;

16. Find the birthday of employee Pat Tin. 'd IS NULL'

select birthdate
from employee
where name='Pat Tin';

17. List the information on those born on Jan. 1, 1970. '(d1,i2)OVERLAPS(d3,d4)'

select *
from employee
where birthdate <= date'01/01/1970' and date'01/01/1970' <= birthdate+0;

Example queries for datetime constructors of instants and intervals:

18. List the information on those ten days older than those born on Feb. 15, 1970. 'd+i'

select *
from employee
where birthdate+10=date'02/15/1970';

19. List the information on those ten days younger than those born on Feb. 5, 1970. 'i+d'

select *
from employee
where 10+date'02/05/1970'=birthdate;

20. List the information on those ten days older than those born on Feb. 15, 1970. 'd-i'

select *
from employee
where date'02/15/1970'-10=birthdate;

Example queries for interval constructors of instants and intervals:

21. List the information on those ten days younger than those born on Feb. 5, 1970. 'i1+i2'

select *
from employee
where 10+0=birthdate-date'02/05/1970';

22. List the information on those ten days younger than those born on Feb. 5, 1970. 'i1-i2'

select *
from employee
where 15-5=birthdate-date'02/05/1970';

23. List the information on those ten days younger than those born on Feb. 5, 1970. 'd1-d2'

select *
from employee
where birthdate-date'02/05/1970'=10;

24. How many days younger are those born on Feb. 15 than those born on Jan.1, 1970? 'd1-d2'

select date'02/15/1970'-date'01/01/1970'
from employee;

25. List the information on those ten days younger than those born on Feb. 5, 1970. 'i*n'

select *
from employee
where 10*1=birthdate-date'02/05/1970';

26. List the information on those ten days older than those born on Feb. 15, 1970. 'n*i'

select *
from employee
where 1*10=date'02/15/1970'-birthdate;

27. List the information on those ten days younger than those born on Feb. 5, 1970. 'i1/i2'

select *
from employee
where 10/1=birthdate-date'02/05/1970';

28. List the information on those ten days older than those born on Feb. 15, 1970. '+i'

select *
from employee    
where date'02/15/1970'-birthdate=(+10);

29. List the information on those ten days younger than those born on Feb. 5, 1970. '-i'

select *
from employee
where date'02/05/1970'-birthdate=-10;

Example queries for other operators of instants and intervals:

30. List information on those born on Jan. 1, 1970. 'CAST(d AS DATE)'

select cast(birthdate as date)
from employee
where birthdate=date'01/01/1970';

31. List information on those whose project due time is 12:00:30 pm. 'CAST(d AS TIME)'

select cast(project_time as time)
from employee
where project_time=time'12:00:30 pm';

32. What's the date of checkin time of 8:10:10 am on Feb. 1,1997? 'CAST(d AS TIMESTAMP)(where d is a DATE)'

select cast (checkin_time as date)
from employee
where checkin_time='02/01/1997 8:10:10 am';

33. What's the time of checkin time '02/01/1970 8:10:10 am'? 'CAST(d AS TIMESTAMP)(where d is a TIME)'

select cast (checkin_time as time)
from employee
where checkin_time='02/01/1997 8:10:10 am';

34. Show the character string of Jan. 1, 1970. 'CAST(d AS CHAR)'

select cast (birthdate as char(10))
from employee
where birthdate='01/01/1970';

35. Show the character string of interval of 10 days. 'CAST(i AS CHAR)'

select cast (10 as char(2))
from employee;

36. Show the date that Feb.15 is later than Feb. 5, 1970. 'CAST(i AS INTEGER) (where i is a DAY)'

select cast (date'02/15/1970'-date'02/05/1970' as integer)
from employee
where date'02/15/1970'-date'02/05/1970'=10

37. Show the time that 9:20:30 is later than 9:10:20 am on Feb. 1, 1997. 'CAST(i AS INTEGER) (where i is a SECOND)'

select cast (timestamp'02/01/1997 9:20:30 am'-timestamp'02/01/1997 9:10:20 am' as integer)
from employee
where timestamp'02/01/1997 9:20:30 am'-timestamp'02/01/1997 9:10:20 am'=610;

38. List the information on those born on Jan. 1, 1970. 'EXTRACT(DAY from d)'

select *
from employee
where extract(year from birthdate)=1970
and extract(month from birthdate)=1
and extract(day from birthdate)=1;

Example queries for predicates of periods:

39. Show the begin and end date of two same periods from Feb. 5 to Feb. 15, 1970. 'p equals q'

select birthdate
from employee
where birthdate=date'02/05/1970' or birthdate=date'02/15/1970';

40. Find the end date in the period before the period from Feb. 15, 1970 to Apr. 20, 1971, and begin from Jan. 1, 1970. 'p before q (here p=[1970-01-01, birthdate], q=[1970-02-15, 1971-04-20])'   

select birthdate
from employee
where date'01/01/1970' < birthdate and birthdate < date'02/15/1970';

41. Find the end date in the period before the period from Apr. 20, 1971 to May 10, 1972, and begin from Feb. 5, 1970. 'p before-1 q (here q=[1970-02-05, birthdate], p=[1971-04-20, 1971-05-10])'

select *
from employee
where date'02/05/1970' < birthdate and birthdate < date'04/20/1971';

42. Find the end date in the period meets the period from Feb. 5, 1970 to Feb. 15, 1970, and begin from Jan. 1, 1970. 'p meets q (here p=[1970-01-01, birthdate), q=[1970-02-05, 1970-02-15))'

select * 
from employee
where date'01/01/1970' < birthdate and birthdate = date'02/05/1970';

43. Find the end date in the period meets the period from Feb. 15, 1970 to Apr. 20, 1971, and begin from Feb. 5, 1970. 'p meets-1 q (here q=[1970-02-05, birthdate), p=[1970-02-15, 1971-04-20))'

select *
from employee
where date'02/05/1970' < birthdate and birthdate = date'02/15/1970';

44. Find the begin date in the period overlaps the period from Feb. 05, 1970 to May 10, 1972, and end with Feb. 15, 1970. 'p overlaps q (here p=[birthdate, 1970-02-15), q=[1970-02-05, 1972-05-10))'

select *
from employee
where birthdate<date'02/05/1970';

45. Find the begin date in the period overlaps the period from Feb. 15, 1970 to May 10, 1972, and end with Apr. 20, 1971.  'p overlaps-1 q (here q=[birthdate, 1971-04-20), p=[1970-02-15, 1972-05-10))'

select *
from employee
where birthdate < date'02/15/1970';

46. Find the end date in the period during the period from Jan. 1, 1970 to Apr. 20, 1971, and begin from Feb. 5, 1970.  'p during q (here p=[1970-02-05, birthdate), q=[1970-01-01, 1971-04-20))'

select *
from employee
where date'02/05/1970' < birthdate and birthdate < date'04/20/1971';

47. Find the end date in the period during the period from Feb. 5, 1970 to Apr. 20 , 1971, and begin from Feb. 15, 1970.  'p during-1 q (here q=[1970-02-15, birthdate), p=[1970-02-05, 1971-04-20))' 

select *
from employee
where date'02/05/1970' < birthdate and birthdate < date'04/20/1971';

48. Find the end date in the period that starts the period from Jan. 1, to Feb. 15, 1970.  'p starts q (here p=[1970-01-01, birthdate), q=[1970-01-01, 1970-02-15))'

select *
from employee
where date'01/01/1970' < birthdate and birthdate < date'02/15/1970';

49. Find the end date in the period that starts the period from Feb. 15, to May 10, 1972.  'p starts-1 q (here q=[1970-02-15, birthdate), p=[1970-02-15, 1972-05-10)) 

select *
from employee
where date'02/15/1970' < birthdate and birthdate < date'05/10/1972';

50.  Find the beginning date in the period that finishes the period from Jan. 1 to Feb. 15, 1970.  'p finishes q (here p=[birthdate, 1970-02-15), q=[1970-01-01, 1970-02-15))'

select *
from employee
where birthdate < date'02/15/1970' and date'01/01/1970' < birthdate;

51. Find the beginning date in the period that finishes the period from Feb. 5, 1970 to Apr. 20, 1971.  'p finishes-1 q (here q=[birthdate, 1971-04-20), q=[1970-02-05, 1971-04-20))'

select *
from employee
where birthdate < date'4/20/1971' and date'02/05/1970' < birthdate;

Example queries for datetime constructors of periods:

52. List the information on those whose birth date begins the period from Feb. 5 to Feb. 15, 1970.  'beginning(p) (here p=[1970-02-05, 1970-02-15])'

select *
from employee
where birthdate = date'02/05/1970';

53. What's the previous date of the day '1970-02-05'?  'previous(p) (here p=[1970-02-05, 1970-02-15])'

select date'02/05/1970'-1
from employee;

54. What's the last date of the period from the oldest birth date to the youngest birth date?  'last(p) (here p=[1970-01-01, birthdate))'  

select max(birthdate)-1
from employee;

55. What's the ending date of the period from the oldest birth date to the youngest birth date?  'ending(p) (here p=[1970-01-01, birthdate])'  

select max(birthdate)
from employee;

Example queries for interval constructors of periods: 

56. What's the duration of the period from the oldest birth date to the youngest birth date?  'duration(p), (here p=(1970-01-01, 1972-05-20))' 

select date'05/20/1972'-date'01/01/1970'
from employee;

Example queries for period constructors of periods:

57.  List the information on those whose birth date begins the period that finishes on Feb.5, 1970.  'p+i (here p=[birthdate, 1970-02-05], i=10)' 

select *
from employee
where birthdate+10 < date'02/05/1970'+10;

58. List the information on those whose birth date begins the period that finishes on Feb.5, 1970.  'i+p (here p=[birthdate, 1970-02-05], i=20)'

select *
from employee
where 20+birthdate < 20+date'02/05/1970';

59. List the information on those whose birth date begins the period that finishes on Feb.5, 1970.  'p-i (here p=[birthdate, 1970-02-05], i=30)'
 
select *
from employee
where birthdate-30 < date'02/05/1970'-30;






Qing Yan
CS560 Project
Sample Queries
12/03/1997



