很简单的问题 : 虚心求教在线等

HooverHuang 2009-10-27 12:13:43
1.我有一张表中有个字段是datetime类型的,存进去的时候后面是有详细时间的。
能通过 SQL语句只查出这个字段的 日期部分不要时间吗 ?怎么写??



2.有张表有个外键ID:userID

我想查询 去掉 userID 字段重复记录的所有数据 。。。换句话说就是所有userID的记录只取一条。。。
怎么写 ???

谢谢
...全文
80 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
taoistong 2009-10-27
  • 打赏
  • 举报
回复


1、select convert(char(10),getdate(),120)
2、
select *
from (select rownumber() over (partition by id order by id) as taoistong , * from tb )t
where taoistong =1

sea0302 2009-10-27
  • 打赏
  • 举报
回复
修改一下第2个,字段没看清楚是useid
select * from tb t where not exists (select * from tb where name=t.name and userid<t.userid)
sea0302 2009-10-27
  • 打赏
  • 举报
回复
1、select convert(varchar(10),getdate(),120)
2、select * from tb t where not exists (select * from tb where name=t.name and id<t.id)
华夏小卒 2009-10-27
  • 打赏
  • 举报
回复

select * from tb t
where not exists(select * from tb where userid=t.userid and id>t.id)
华夏小卒 2009-10-27
  • 打赏
  • 举报
回复

select convert(varchar(10),getdate(),120)

2009-10-27

(1 行受影响)
7761098 2009-10-27
  • 打赏
  • 举报
回复
1。 SELECT convert(varchar, getdate(), 112) -- yyyymmdd
2. select distinct userID from ...
HooverHuang 2009-10-27
  • 打赏
  • 举报
回复
第一个问题解决了 1。 SELECT convert(varchar, getdate(), 112) -- yyyymmdd

但是第二个,我还要一起查其他字段呢 ,select distinct userID from ... 这个只能查一个字段啊 。

提醒下,两个问题没联系的,也是不同德两张表 ???
BriskJJ 2009-10-27
  • 打赏
  • 举报
回复
mark

22,206

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧