Like和DisLike的SQL数据库结构 [英] SQL database structure for Like and DisLike

查看:836
本文介绍了Like和DisLike的SQL数据库结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Web编程,需要一些专家的建议。
我使用SQL数据库为我的一个网站项目。
我的网站将显示一个包含喜欢和不喜欢按钮的主题列表。登录的用户将能够点击每个主题的喜欢或不喜欢按钮。
我可以保存每个主题的喜欢和不喜欢数。因此,如果用户点击某个主题,它会显示该特定主题的喜欢和不喜欢次数,但我想实现的是当有人点击特定的用户个人资料时,它应该显示所有用户喜欢或不喜欢的主题。
例如,当我们在Facebook上点击用户个人资料时,会显示该特定用户的所有评论或喜好,如何做类似的操作。我想知道数据结构来实现这个和查询数据
谢谢大家。
Regards,
Aaf。

I am new to web programming and need some expert advise. I am using SQL database for one of my website project. My website will display a list of topics with a Like and Dislike button. Logged in users will be able to click on the Like or dislike button for each topic. I am able to keep a count of likes and dislikes for each topics. So if a user clicks on a certain topic it will display the number of Likes and Dislikes for that particular topic, however what I am trying to achieve is when someone clicks on a particular Users profile it should display all the topics that user likes or dislikes. For example when we click on a users profile in Facebook, it displays all the comments or Likes of that particular user, how do I do something similar to that. I would like to know the data structure to implement this and query the data Thank you all. Regards, Aaf.

推荐答案

这是一个可以使用的简单模式。

This is a simple schema you could use. isLike is a boolean, true if it's a like, false if it's a dislike.

按主题查询总喜欢次数

    Select Count(*), Topic,isLike FROM LikesDislikes GROUP BY Topic,isLike

对于所有用户喜欢的主题

For all of a user's liked topics

   SELECT topic FROM likesdislikes WHERE userName = 'user' AND isLike = true;

等等。

这篇关于Like和DisLike的SQL数据库结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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