MySQL SELECT 女性不是男性

编程入门 行业动态 更新时间:2024-10-24 22:18:17
本文介绍了MySQL SELECT 女性不是男性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的数据库中有一个名为类别的字段,其中包含服装店主题的类别(新到货、畅销商品、男士、女士、儿童等)

I have a field in my database called categories which holds the categories of a clothing store topics (New Arrival, Top Sellers, Men, Women, Kids etc)

我有一张唱片:New Arrival, Men我有第二个记录:New Arrival, Women

I have one record that has: New Arrival, Men I have a second record that has: New Arrival, Women

如何查询数据库以只选择女性或男性?

How could I query the database to select just women or just men?

我已经厌烦了:SELECT * FROM products WHERE Categories RLIKE [[:<:]]Men[[:>:]]'

这对男性有效,但对女性无效.

This does work for men but it doesn't work for women.

推荐答案

好吧,如果您实际上存储词Men"或Women",那么您的数据库设置不正确

Well if you are actually storing the words "Men" or "Women", your database is set up incorrectly

您应该使用链接表让我们说 categories 将产品链接到类别.

You should be using a linked table let us say categories to link products to categories.

然后您可以执行以下操作:

Then you can do something like:

SELECT * FROM products p JOIN categoriesToProducts ctp ON ctp.productId = p.productId JOIN categories c ON c.categoryId = ctp.categoryId WHERE c.categoryName = "Men";

更多推荐

MySQL SELECT 女性不是男性

本文发布于:2023-10-30 23:55:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:男性   女性   MySQL   SELECT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!