用户活动或单选查询的单独表

发布于 2024-11-09 20:24:40 字数 219 浏览 3 评论 0原文

我正在为我的客户创建一个社交网络,他们需要类似 facebook 的墙和用户最近的活动。

我有大约 8 个表,分别表示用户帐户、信息、群组、评论、页面、照片库、喜欢、分享。

用户个人资料中,他们需要用户在网站中的整个活动。

我可以使用单个连接查询吗?或者需要有单个表作为最近活动

I am creating a social network for my client where they need facebook-like wall and user recent activity.

I have around 8 table says user account , info , groups , comments , page , photogallery, likes , shares.

In the user profile, they need the entire activity of the user in the site.

Can I use a single Join Query or need to have a individual table as recentactivity.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀梦 2024-11-16 20:24:41

您可以使用联合查询从不同的表中提取数据并将其存储在视图中。这是总体思路...

create view 'v_recent_activity' as 
select user_id, 'comment' as action, comment_text as action_info, comment_date as action_date from comments
union
select user_id, 'photo' as action, photo_url as action_info, photo_date as action_date from photos
union
select user_id, 'page' as action, page_url as action_info, comment_date as action_date from pages
union
select user_id, 'likes' as action, like_info as action_info, comment_date as action_date from likes
union
select user_id, 'shares' as action, share_info as action_info, share_date as action_date from shares

然后您可以使用类似

Select * from v_recent_activity where action_date between <begin_date> and <end_date>

或 的连接来访问它

Select a.*, b.* from users a join v_recent_activity b on a.id = b.user_id where a.id = <user_id> and b.action_date between <begin_date> and <end_date>

You could have a union query to pull data from the different tables and store in a view. Here's the general idea...

create view 'v_recent_activity' as 
select user_id, 'comment' as action, comment_text as action_info, comment_date as action_date from comments
union
select user_id, 'photo' as action, photo_url as action_info, photo_date as action_date from photos
union
select user_id, 'page' as action, page_url as action_info, comment_date as action_date from pages
union
select user_id, 'likes' as action, like_info as action_info, comment_date as action_date from likes
union
select user_id, 'shares' as action, share_info as action_info, share_date as action_date from shares

Then you could access it with something like

Select * from v_recent_activity where action_date between <begin_date> and <end_date>

or with a join

Select a.*, b.* from users a join v_recent_activity b on a.id = b.user_id where a.id = <user_id> and b.action_date between <begin_date> and <end_date>
小ぇ时光︴ 2024-11-16 20:24:41

您可以考虑创建一个 logactivity 表来包含其最近活动的记录。这样您只需要一个查询。您将根据活动类型连接其他表。

You might consider creating a log or activity table that would contain the record of their recent activity. This way you only need a single query. You would join the other tables based on the activity type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文