一个SQL查询语句

来源:百度知道 编辑:UC知道 时间:2024/06/12 10:15:49
存在表Person(name,birth_date,sex,salary),要查询1979年上半年出生的所有人,请写出SQL。
数据库是ORACLE,好像要用到日期转化,不能直接写成
betwween 1979-01-01 and 1979-06-30

select *
from Person
where birth >= to_date('1979-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
and birth <to_date('1979-07-01 00:00:00','yyyy-mm-dd hh24:mi:ss')

oracle 用to_date函数将字符串转换为时间型

日期用用井号,正解~~#####

但语法应该是between and...

--------
你把
回答者:MasterZheng - 童生 一级 7-1 22:12
回答者:wanjiexi6688 - 初学弟子 一级 7-1 22:32
的答案结合一下就好了。

数据库是Oracle SQLServer 还是MySQL什么的,语句会有区别
Oracle:select *
from Person
where birth_date >= to_date('19790101000000','YYYYMMDDHH24MISS')
and birth_date <=to_date('19790630235959','YYYYMMDDHH24MISS') ;

select * from Person where birth_date between #1979-1-1# AND #1979-6-30#

use(数据库名)
select * from Person where birth_date between #1979-1-1# to #1979-6-30#