sqlserver问题。求思路

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver问题。求思路相关的知识,希望对你有一定的参考价值。

如图,我想根据uid分组,求得第二小的日期与第三小的日期之间的间隔天数,如何做到这点?求sql指导

select t1.uid,datediff(dd,t1.adate,t2.adate) from
(select * from test a where (select count(*) from test b where a.uid=b.uid and b.adate<a.adate) between 1 and 2) t1,
(select * from test a where (select count(*) from test b where a.uid=b.uid and b.adate<a.adate) between 1 and 2) t2
where t1.uid=t2.uid and t2.adate>t1.adate

表名test,自己换一下
参考技术A select uid,
datediff(day,max(case when MYID = 3 then adate else null end),
max(case when MYID = 2 then adate else null end)) as 间隔天数
from
(select ROW_NUMBER() OVER(PARTITION BY UID ORDER BY adate DESC) as MYID,adate,uid from test) a
group by uid
参考技术B ;with cte as(select *,row_number() over(partition by uid order by adate)rn from tb)
select a.*,b.*,datediff(day,a.adate,b.adate) from cte a,cte b where a.uid=b.uid and a.rn=2 and b.rn=3
参考技术C 假设表名是:table

select uid,
(select top 1 t2.adate from(select top 2 adate from table t1 where t1.uid=t.uid order by t1.adate asc) t2 order by desc) min2,
(select top 1 t3.adate from(select top 3 adate from table t4 where t4.uid=t.uid order by t4.adate asc) t3 order by desc) min2,
from table t group by uid

MyEclipse 用户sa 登录失败 sqlserver 设置过了 分不多求帮忙

参考技术A 1 url问题?
2 用户密码错误?
3 驱动文件问题?
注意SQL Server版本跟驱动jar版本是敏感关联的
参考技术B

    检查你驱动包是不是放错了?

    检查connection url写的是否正确


追问

驱动包不是放在tomcat的lib文件夹中吗?

追答

你这是连接数据库,又不是项目部署,放在tomcat里面干啥?

追问

应该放在哪里啊?

参考技术C 没驱动包,需要添加三个包追问

添加哪三个包?

追答

就是你放在lib文件夹下的驱动包啊

本回答被提问者采纳

以上是关于sqlserver问题。求思路的主要内容,如果未能解决你的问题,请参考以下文章

sqlserver怎么能让视图更新数据库数据?求高手

求一个sqlserver2008R2的安装包

sqlserver2000,为啥执行时很慢?仅仅是300条数据。求大神帮助

阿里云ECS安装sqlserver,本地无法连接问题排查思路

07-SQLSERVER聚合函数

sqlserver 存储过程 使用事务,说明在下边,求大神指教!