php/MySQL 比较列
我是 MySQL 查询的新手,也是 PHP 的初学者,所以我希望得到一些关于这个问题的帮助。
这是我的场景: 我有一个系统,允许用户将喜爱的项目保存到数据库中。这些项目有大约 20 个不同的特征(数据库列),并且每个项目仅包含一些特征。
我想要做的是编写一个查询,查看用户最喜欢的项目并将它们与数据库中的其他条目(行)进行比较,如果它们具有相同数量或更多的功能,我希望系统创建 PDF 和电子邮件给他们。每个功能列都有文本“in”(如果包含)。
我不需要 PDF 或电子邮件部分的帮助,只需要 MySQL/PHP 部分。
我非常感谢任何有帮助的帮助、见解或 SQL 查询。感谢您抽出时间。
更新:
感谢您的快速回复。然而,我仍然很困惑,而且我实际上遗漏了一个细节。在某些字段中,有文本 n/a,因此值不为空,但我不希望包含它。什么是“项目的 FK”。有没有什么方法可以计算包含文本“in”的列,而不是相反 - 计算所有空值?任何代码示例都会很棒。
感谢您的帮助。
I am new to MySQL queries and a beginner at PHP, so I would love some help with this question.
Here is my scenario:
I have a system that allows users to save favourite items to the database. These items have about 20 different features (db columns) and only some features are included for each item.
What I want to do is write a query that looks at the users favourite items and compares them to other entries (rows) in the database and if they have the same number of features or more, I want the system to create a PDF and email it to them. Each feature column has the text "in" if it's included.
I don't need help with the PDF or email portion, just the MySQL/PHP portion.
I would very much appreciate any help, insight, or SQL queries that would be of help. Thank you for your time.
Update:
Thanks for your quick reply. I, however, am still confused and I actually left out a detail. In some of the fields, there is the text n/a, so the values not null, but I don't want it to be included. What is an "FK to the item". Are there any ways to counting the columns that include the text "in", instead of the reverse - counting all null values? Any examples of code would be amazing.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您对功能表中的项目有 FK。您应该将每个功能列的默认值设置为 NULL,然后使用 如何计算表中所有 NULL 值的数量? 其中有一个查询将为您提供一行和所有 NULL 列的计数。只需运行一遍,您就会知道每个项目有多少功能处于活动状态。
I am assuming you have a FK to the item in your features table. You should set the default value of each of your feature column to NULL, then use the query from How to count all NULL values in a table? which has a query that will give you a row and the count of all NULL columns. Simply run through that and you'll know how many features are active for each item.