我的数据库中有一个名为类别的字段,其中包含服装店主题的类别(新到货、畅销商品、男士、女士、儿童等)
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 女性不是男性
发布评论