Mysql sql语句order by with条件始终失败?
我想显示所有具有自定义订单的行,在第一行中,部分行的数据与2天前到当前日期(使用2016-06-18作为当前日期)的数据相同,之后请根据最小的距离数自定义行, 我使用此sql检索数据,但总是失败Mysql sql语句order by with条件始终失败?,mysql,sql,Mysql,Sql,我想显示所有具有自定义订单的行,在第一行中,部分行的数据与2天前到当前日期(使用2016-06-18作为当前日期)的数据相同,之后请根据最小的距离数自定义行, 我使用此sql检索数据,但总是失败 SELECT pwaktuserver as date, acos(cos(-7.47353794753 * (PI()/180)) * cos(112.343534533 * (PI()/180)) * cos(plat * (P
SELECT pwaktuserver as date,
acos(cos(-7.47353794753 * (PI()/180)) *
cos(112.343534533 * (PI()/180)) *
cos(plat * (PI()/180)) *
cos(plong * (PI()/180))
+
cos(-7.47353794753 * (PI()/180)) *
sin(112.343534533 * (PI()/180)) *
cos(plat * (PI()/180)) *
sin(plong * (PI()/180))
+
sin(-7.47353794753 * (PI()/180)) *
sin(plat * (PI()/180))
) * 3959 as Dist
FROM tbpos INNER JOIN tbanggota ON tbanggota.id_a = tbpos.id_a WHERE stsTampil <> '2'
GROUP BY tbpos.posid
ORDER BY case when date(pwaktuserver)>=curdate()-2 then Dist*(-1) else Dist end
选择pwaktuserver作为日期,
acos(cos(-7.47353794753*(PI()/180))*
cos(112.343534533*(PI()/180))*
cos(平台*(PI()/180))*
cos(plong*(PI()/180))
+
cos(-7.47353794753*(PI()/180))*
sin(112.343534533*(PI()/180))*
cos(平台*(PI()/180))*
sin(plong*(PI()/180))
+
sin(-7.47353794753*(PI()/180))*
sin(平台*(PI()/180))
)*3959 as区
从tbpos内部连接tbanggota.id_a=tbpos.id_a上的tbanggota,其中stsTampil“2”
按tbpos.posid分组
当日期(pwaktuserver)>=curdate()-2时按大小写排序,然后按Dist*(-1)其他Dist结束
上面sql语句的结果
注:1。黄色框是由2天前的日期组成的行组
排序数据返回正确值黄色框作为第一部分,蓝色框作为第二部分,但我的问题是黄色框中的日期未排序描述,我想使黄色框排序描述,我如何实现我的目标?谢谢只需添加另一个条件
ORDER BY CASE WHEN date(pwaktuserver)>=curdate()-2 THEN date(pwaktuserver)
ELSE null
END DESC,
CASE WHEN date(pwaktuserver)>=curdate()-2 THEN Dist*(-1)
ELSE Dist
END ASC -- OR DESC
只需添加另一个条件
ORDER BY CASE WHEN date(pwaktuserver)>=curdate()-2 THEN date(pwaktuserver)
ELSE null
END DESC,
CASE WHEN date(pwaktuserver)>=curdate()-2 THEN Dist*(-1)
ELSE Dist
END ASC -- OR DESC
博奥姆。。。为什么我现在问而不是昨天,谢谢你的回答,我是昨天来的。你是火箭人…好家伙。。。为什么我现在问而不是昨天,谢谢你的回答,我是昨天来的。你是火箭人。。。