我有一个SQL查询,从表中取经纬度,并将其与我的位置设置latitiude和经度比较。我希望能够有一个案例声明,将英里分成我的其他专栏。我不能得到这个SQL查询来把我的距离,并在案件陈述中放入类别
*在这里,我走的纬度和经度来自人民,从一组点发现距离,使之成为一个名为万里
Select
(
3959 * acos (
cos (radians(43.7779))
* cos(radians(fc.Address1_Latitude))
* cos(radians(fc.Address1_Longitude) - radians(-88.4215))
+ sin (radians(43.7779))
* sin(radians(fc.Address1_Latitude))
))
As Miles
from filteredcontact fc
**以下字段是哪里出了问题,我想采取我发现的里程,并试图在下一个案例陈述中列入类别。举例来说,任何距离校园0-24英里的人都希望它能够提出多少个询问,申请人,确认等等。我想为每一组距离做这件事。
select case
WHEN 'Miles' < 25 THEN '0-24'
WHEN 'Miles' <= 25 and 'Miles' <49 THEN '25-49'
WHEN 'Miles' >= 50 and 'Miles' < 74 THEN '50-74'
WHEN 'Miles' >= 75 and 'Miles' < 99 THEN '75-99'
WHEN 'Miles' >= 100 and 'Miles' < 125 THEN '100-125'
WHEN 'Miles' >= 126 and 'Miles' < 151 THEN '126-151'
WHEN 'Miles' >= 152 and 'Miles' < 177 THEN '152-177'
WHEN 'Miles' >= 178 and 'Miles' < 203 THEN '178-203'
WHEN 'Miles' >= 204 and 'Miles' < 229 THEN '204-229'
WHEN 'Miles' >= 230 and 'Miles' < 255 THEN '230-255'
WHEN 'Miles' >= 256 and 'Miles' < 281 THEN '256-281'
WHEN 'Miles' >= 282 and 'Miles' < 307 THEN '282-307'
WHEN 'Miles' >= 308 and 'Miles' < 333 THEN '308-333'
WHEN 'Miles' >= 334 and 'Miles' < 359 THEN '334-359'
WHEN 'Miles' >= 360 and 'Miles' < 385 THEN '360-385'
WHEN 'Miles' >= 386 and 'Miles' < 411 THEN '386-411'
WHEN 'Miles' >= 412 and 'Miles' < 437 THEN '412-437'
WHEN 'Miles' >= 438 and 'Miles' < 463 THEN '438-463'
WHEN 'Miles' >= 464 and 'Miles' < 489 THEN '464-489'
WHEN 'Miles' >= 490 and 'Miles' < 500 THEN '490-500'
ELSE 'over 500'
END
**这里是它需要的地方,并把上面的英里放到列中。
sum (case when fc.datatel_prospectstatusname in ('Prospect','Inquiry', 'Applicant', 'Admit',
'Confirmed', 'Enrolled', 'Application Started', 'Application Submitted',
'Application Completed', 'Application Moved to ERP') then 1 else NULL End) as "INQ",
sum (case when fc.datatel_prospectstatusname in ('Applicant','Admit', 'Confirmed', 'Enrolled',
'Application Submitted', 'Application Completed',
'Application Moved to ERP')then 1 else NULL End) as "APP",
(select cast (sum(case when fc.datatel_prospectstatusname in ('Applicant','Admit', 'Confirmed',
'Enrolled', 'Application Submitted', 'Application Completed',
'Application Moved to ERP') then 1 else NULL End)as float)/
(sum (case when fc.datatel_prospectstatusname in ('Prospect','Inquiry', 'Applicant', 'Admit',
'Confirmed', 'Enrolled', 'Application Started', 'Application Submitted',
'Application Completed', 'Application Moved to ERP') then 1 else NULL End))) "APP/INQ",
sum (case when fc.datatel_prospectstatusname in ('Admit', 'Confirmed',
'Enrolled') then 1 else NULL End) as "ADM",
(select cast (sum(case when fc.datatel_prospectstatusname in ('Admit', 'Confirmed',
'Enrolled') then 1 else NULL End)as float)/
(sum (case when fc.datatel_prospectstatusname in ('Applicant','Admit', 'Confirmed', 'Enrolled',
'Application Submitted', 'Application Completed',
'Application Moved to ERP') then 1 else NULL End))) "ADM/APP",
sum (case when fc.datatel_prospectstatusname in ('Confirmed', 'Enrolled') then 1 else NULL End) as "DEP",
(select cast (sum(case when fc.datatel_prospectstatusname in ('Confirmed', 'Enrolled') then 1 else NULL End)as float)/
(sum (case when fc.datatel_prospectstatusname in ('Admit', 'Confirmed',
'Enrolled') then 1 else NULL End))) "DEP/ADM",
sum (case when fc.elucnsrv_currentprimaryappstatusname Like '%Canceled%' then 1 else NULL End) as "CAN",
(select cast (sum(case when fc.elucnsrv_currentprimaryappstatusname Like '%Canceled%' then 1 else NULL End)as float)/
(sum (case when fc.datatel_prospectstatusname in ('Confirmed', 'Enrolled') then 1 else NULL End))) "CAN/DEP"
sum (case when fc.datatel_prospectstatusname ='Enrolled' then 1 else NULL end) as "ENR",
(select cast (sum(case when fc.datatel_prospectstatusname ='Enrolled' then 1 else NULL End)as float)/
(sum (case when fc.datatel_prospectstatusname in ('Admit', 'Confirmed', 'Enrolled') then 1 else NULL End))) "ENR/ADM"
FROM FilteredContact fc
where fc.Address1_Latitude is not null
and fc.Address1_Longitude is not null
and fc.FirstName is not null
and fc.LastName is not null
and fc.datatel_academiclevelofinterestidname in ('PreProfessional' , 'Undergraduate' , 'Special')
and (fc.statecodename = 'Active' and fc.customertypecodename = 'Prospective Student')
group by fc.address1_latitude, fc.address1_longitude
您能否提供一个您希望输出看起来像什么的例子?一个简单的输入矩阵可以帮助人们理解你的问题。 – SlimsGhost
这是'Case'声明中的问题吗?因为它将'String''Miles'与'int'进行比较,并且它总是错误的。 – Caveman42
看下面的打印屏幕 – user3629893