我如何获得最短约会 [英] How do I get minimum date

查看:135
本文介绍了我如何获得最短约会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得访问的最短日期。我试图第一次访问这个人。这是我的整个人列表。

这是我的查询:

 声明  @ dateDate   as   DateTime  
设置 @ dateDate = SYSDATETIME()

select distinct a.PatientName,
a.PatientSSN,
CONVERT 日期 @ dateDate AS FIRSTVISIT
来自 SPatient.SPatient a
JOIN OUTPAT.VISIT AS D
ON A.PATIENTSID = D.PATIENTSID
加入 Dim.Location 作为 c
D. LocationSID = c.LocationSID
其中 c.locationname 喜欢 ' %wi - %'
c.LocationName 喜欢 ' %wi-PHONE%'
c.LocationName 喜欢 ' %non va%'
c.LocationName 喜欢 ' %ds%'
group by a.patientname,a.patientssn
order by a.patientname,a.patientssn

解决方案

尝试使用MIN功能



SELECT PatientName,Location,Min(visitdate)

来自mytable

group by PatientName,Location

How do I get the minimum date for a visit. I am trying to get the first time the person had a visit. This is for my entire person listing.
Here is my query:

Declare @dateDate as DateTime
Set @dateDate = SYSDATETIME()

select distinct a.PatientName,
       a.PatientSSN,
       CONVERT(Date, @dateDate) AS FIRSTVISIT
from    SPatient.SPatient as a
    JOIN OUTPAT.VISIT AS D
        ON A.PATIENTSID=D.PATIENTSID
    join Dim.Location as c
        on D.LocationSID=c.LocationSID
where c.locationname like '%wi-%'
      and c.LocationName not like '%wi-PHONE%'
      and c.LocationName not like '%non va%'
      and c.LocationName not like '%ds%'
group by a.patientname, a.patientssn
order by a.patientname, a.patientssn

解决方案

Try using the MIN Function

SELECT PatientName, Location, Min(visitdate)
from mytable
group by PatientName, Location


这篇关于我如何获得最短约会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆