数据库中的表leve , 字段为 id , add_date
add_date的格式为:
id add_date
1 2012-10-24 7:00:00
2 2012-10-24
3 2012-10-25 7:00:00
4 2012-12-24 7:00:00
假如我要查询所有2012年10月的所有数据怎么写SQL语句?
应该是查处id 1 , 2, 3
3条数据
不是oracle 是PostgreSQL
不对。
column "month" does not exist
SELECT * FROM leve WHERE datediff(month,add_date,'2012-10-01')=0
这里你得看到一个问题,复制到SQL执行页面时,注意单引号。如果你那边还报错的话,请问你的是SQL Server数据库吗?我这边运行是正常的。
sorry是PostgreSQL不是oracle
不对
function nvarchar(integer) does not exist
什麼情况?你是什麼环境啊?
追问不是oracle 是PostgreSQL
追答哦...我这只适用SQL SERVER
这些23,7是什么???
追答CONVERT(varchar(100), hire_date, 23) 查询 葛时 2006-05-16
left (,7)是取左边起7位数
oracle
select * from leve where to_date(add_date ,'YYYY-Mm')='2012-10'
sorry不是oracle
是PostgreSQL