在MySQL中仅从日期时间(YYYY-MM-DD HH:MM:SS)中按日期选择不同的日期 [英] Selecting a distinct date by day only from datetime (YYYY-MM-DD HH:MM:SS) in MySQL

查看:373
本文介绍了在MySQL中仅从日期时间(YYYY-MM-DD HH:MM:SS)中按日期选择不同的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行此命令将带给我以下内容(所有列中的所有日期,因此它基本上与SELECT日期执行相同的操作,但没有不同):

Executing this command brings me the following (all the dates from all columns, so it essentially did the same thing as SELECT date without distinct):

SELECT DISTINCT date FROM daily ORDER BY date DESC

2013-02-12 16:40:52
2013-02-06 11:48:49
2013-02-06 11:36:41
2013-02-06 11:35:59
2013-02-04 19:38:12
2013-02-04 18:12:30
2013-02-04 09:58:41
2013-02-04 09:43:01
2013-02-04 09:35:51
2013-02-04 09:30:22
2013-02-04 09:24:57
2013-02-04 09:21:09
2013-02-04 08:50:13

我需要什么:

2013-02-12
2013-02-06
2013-02-04

  1. 是否可以更改日期表并将其转换为YYYY-MM-DD?

  1. Is there any way to alter my date table and convert it to YYYY-MM-DD instead?

如果没有,有没有办法仅根据日期选择不同的日期?

If not, is there a way to select distinct dates based only on the day?

推荐答案

mysql> select DATE_FORMAT(Current_Timestamp, '%c %d %Y') from dual;
+--------------------------------------------+
| DATE_FORMAT(Current_Timestamp, '%c %d %Y') |
+--------------------------------------------+
| 2 12 2013                                  |
+--------------------------------------------+
1 row in set (0.01 sec)

mysql> 

当然您会使用每日"表.

of course you would be using your 'daily' table.

mysql> select DATE_FORMAT(Date, '%c %d %Y') from daily;

或者也许你想要

mysql> select * from daily group by DATE_FORMAT(Date, '%c %d %Y');

这篇关于在MySQL中仅从日期时间(YYYY-MM-DD HH:MM:SS)中按日期选择不同的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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