MySQL SELECT 女性不是男性 [英] MySQL SELECT women not men

查看:30
本文介绍了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 女性不是男性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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