我需要异常的订购mysql结果 [英] I need unusual ordering mysql results

查看:53
本文介绍了我需要异常的订购mysql结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从当前日期开始按升序排序结果

Im trying to order results ASCENDING from the current date

这就是我现在正在使用的内容

this is what im using now;

SELECT * FROM friends JOIN bdays 
ON bdays.user = friends.friendname 
WHERE username = $userid ORDER BY DATE_FORMAT(date, '%m %d')

有什么想法吗?

示例 现在按日期排序,对从一月开始的生日进行排序

example ordering by date now, sorts the birthdays starting at january

我需要的不是从一月开始的列表,而是从当前日期开始的

what i need, is instead of starting the list at january, is starting it from the current date.

所以,而不是;

January
February
March
April
May
June
July
August
September
November
December

它将像这样订购它们;

It will order them like this;

April (current month/day)
May
June
July
August
September
November
December
January
February
March
April (all the way up to yesterday)

推荐答案

您可以尝试:

ORDER BY
   DATE_FORMAT(date,'%m %d') < DATE_FORMAT(NOW(),"%m %d"),
   DATE_FORMAT(date,'%m %d');

首先,根据日期是否小于当前日期进行排序,然后按月份和日期以升序进行排序.

First, order by whether or not the date is less than the current date, then order by month and date in ascending order.

注意 看起来就像Shrapnel上校所指的方法.

NOTE This looks like the method Col. Shrapnel was referring to.

这篇关于我需要异常的订购mysql结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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