简体   繁体   English

教义查询按日期分组

[英]Doctrine query group by date

I am building an application and I want some sort of notification / log type of page intergrated where the user can see his activity. 我正在构建一个应用程序,我希望集成某种通知/日志类型的页面,以便用户可以看到他的活动。 The page needs to look like the following example: 该页面应类似于以下示例:

Today  
[Username] has done [activity] 13:20  
[Username] has done [activity]  11:27  
[Username] has done [activity]  10:53  

Yesterday   
[Username] has done [activity]  13:20  
[Username] has done [activity]  11:27  
[Username] has done [activity]  10:53  

14 februari  
[Username] has done [activity]  13:20  
[Username] has done [activity]  11:27  
[Username] has done [activity]  10:53  

The thing is that I have absolutely no idea where to start. 问题是我完全不知道从哪里开始。 I am thinking of some kind of log table and then log everything that happens in a table. 我正在考虑某种日志表,然后将表中发生的所有事情记录下来。 But how do I need to query to get the above result? 但是我该如何查询以获得上述结果? I really need someone or something to point me to the right direction. 我真的需要某人或某物来指引我正确的方向。

you are on the right direction : Just create your log table like this: 您的方向正确:只需像这样创建日志表:

create table log(
id int not null primary key identity(1,1),
userID int not null,
logdate datetime,
activityID int not null)

assuming you have a users table that contain the users and a Activity table that contains all the possible activities 假设您有一个包含用户的用户表和一个包含所有可能活动的活动表

then you can produce your query joining the 3 tables: 那么您可以生成连接3个表的查询:

select * 
from log l 
     join UserTable u on l.userId=u.UserId 
     join ActivityTable a on l.ActivityId=a.ActivityID

and then format your text based on the select 然后根据选择设置文本格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM