From_unixtime in MySQL implements query by day

Source: Internet
Author: User
Tags how to use sql
Recently done a set of record system, the record to query by day, how many points won every day, how many innings to list. However, how to use SQL to group by day? First of all, our table confirms that we have a timestamp (int (10)), and I use Create_time.

Next, start editing the statement

The From_unixtime function supports converting timestamps to strings, and we convert timestamps to dates

From_unixtime (Create_time, '%y%m month%d day ')

Then, grouped by this date, here's the full SQL statement

Select From_unixtime (create_time, '%y year%m month%d days ') as Day,count (*) as Count,sum (score) as score from T_everygames where user _id = $userid GROUP by from_unixtime (Create_time, '%y year%m month%d day ') Order by 1 limit 0,6

Similarly, can also according to year, month, day, time, cent to group, is not very convenient?

If a string is stored in the database, such as 2018-1-30, then the Date_format () function is used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.