所以我要做的是创建一个请求,该请求将从数据库中获取图像并以这种方式对它们进行排序,以使图像按上载日期进行分组,并按附加的编号进行排序。 在实践上下文中的含义:
Upload-day Number
Picture a: 05-04-2018 6
Picture b: 05-04-2018 3
Picture c: 04-04-2018 11
Picture d: 04-04-2018 10
等等...
我在这里遇到的问题是,如果我按上传的日期进行分组,那么我会得到不同月份和年份的日子,这不是故意的。 当尝试对上传日期进行分组而不包含时间戳时,我只是想不出一种包含年份和月份的方法。
我的当前方法如下:
SELECT picture_id, file_id, posted_at, ..., pf.filename
FROM picture join picturefile pf using (file_id)
WHERE title LIKE %...% %'
GROUP BY YEAR(posted_at), MONTH(posted_at), DAY(posted_at)
ORDER BY likes DESC
LIMIT 1,20;
此处的表格图片包含posts_at属性。
表格图片:
# Name Typ Collation Standart
1 picture_id (PK) int(11)
2 file_idIndex int(11)
3 usernameIndex varchar(25) utf8_general_ci
4 location varchar(250) utf8_general_ci
5 likes int(11) 0
6 title varchar(100) utf8_general_ci
7 posted_at datetime CURRENT_TIMESTAMP
8 description varchar(255) utf8_general_ci
9 rating_sum int(11)
10 rating_count int(11)
11 comment_option int(11)
12 x_coordinate decimal(2,0)
13 y_coordinate decimal(2,0)
表格图片文件:
Name Typ Collation Standart
1 file_id (PK) int(11)
2 filenameIndex varchar(100) utf8_general_ci NULL
3 filetype varchar(10) utf8_general_ci NULL
我的请求:
SELECT picture_id, file_id, username, location, likes, title, posted_at,
description, rating_sum, rating_count, comment_option, x_coordinate,
y_coordinate, pf.filename
FROM picture join picturefile pf using (file_id)
WHERE title LIKE '%these%' or '%really%'
GROUP BY YEAR(posted_at),
MONTH(posted_at), DAY(posted_at)
ORDER BY likes DESC LIMIT 1,20;
预期结果:
All named attributes with
title: timestamp: likes:
these oranges are very orange. 2018-12-13 08:12:13 0
magnificent. they really are. 2018-12-13 08:12:54 0
以上值已在数据库中注册。