如何在MySQL中爆炸并在查询的WHERE子句中使用它 - MySQL [英] How to explode in MySQL and use it in the WHERE clause of the query - MySQL

查看:153
本文介绍了如何在MySQL中爆炸并在查询的WHERE子句中使用它 - MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库表如下。

I have a database table as below.

Promotion_Table

Promotion_Table

id(INT), promotion_name(VARCHAR),......, bungalow_ids(VARCHAR)

我们可以为平房添加促销(23)。所以一行添加了平房id如下。

We can add a promotion for a bungalow(23). So a row is added with the bungalow id as below.

1,我的促销,........,23

1, My Promotion, ........, 23

但如果我单为多个平房添加了促销(23,42),所有ids都保存在 bungalow_ids 列中,如下所示。

But if I single a promotion is added for a multiple bungalows(23,42) all ids are saved in the bungalow_ids column as below.

2,我的促销2,........,23 | 42

2, My Promotion 2, ........, 23 | 42

如果用户搜索特定洋房的促销活动(23)所有促销活动都应显示在结果中。

If a user search for promotion which are for specific bungalow(23) All promotions for the bungalow should be shown in the result.

我有一个如下的查询。

SELECT * FROM Promotion_Table WHERE bungalow_ids = '23'

它只有1行。但实际上第二行应该显示,因为有一个报价。我可以不使用 LIKE ,因为它得到错误的记录。

It only gets 1 rows. But actually 2nd row should be shown too since there is a offer. I can nt use LIKE since it gets wrong records.

由于我已经参考下面的链接,不知道如何在查询中使用它们。

Given that I have already referred below links but I have no idea how to use them in the query.

您可以在MySQL查询中分割/展开字段吗?

等同于explode()在mysql中使用字符串

如何解决这个问题?

推荐答案

使用分隔字符串并尝试此查询

Use , to separate the string and try this query

select * from promotion_table where FIND_IN_SET("23",bungalow_ids)

http://sqlfiddle.com/#!2/7bbcb/1

这篇关于如何在MySQL中爆炸并在查询的WHERE子句中使用它 - MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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