第1个回答 2012-10-11
select userid,left( convert(varchar(10),checktime,108),5) as time
from check where day(checktime)=9
convert(varchar(10),checktime,108)函数、将给定日期字段转换为字符串时间格式、
108:HH:MM:SS(时分秒)
left()函数从左边开始取子串、取N位、
本身按你的数据应该取4位、但是sql上面的108转换的时间格式字符串、<10 的小时数前面加 0、
所以最后取5位,刚好显示 HH:MM(时分)
第2个回答 2012-10-11
sqlserver:
select user,convert(varchar,convert(datetime,checktime),8) as time
from check where day(checktime)=9
第3个回答 2012-10-11
select user , substring( convert(char(8),checktime,108),1,5) as checktime
from table
where datepart(day,checktime)='9'
第4个回答 2012-10-11
oracle数据库的写法
select id,checktime1 from check where to_char(userid,'d')='9'
sql server写法
select id,checktime1 from check where day(userid)=9
第5个回答 2012-10-11
语句的写法与你的数据库有关系 不同的数据库写法不同。不过都是同一个方法。先把你的日期格式转换成字符型 然后截取2012-后面的1位数 判断是否等于9 是的话就提取 条件就是
截取后的数字='9'