在MySQL中使用LIKE运算符和逗号问题

时间:2018-03-19 07:42:44

标签: mysql sql-like

这是我的疑问:

var shouldShowEmpty = true

func viewDidLoad() {
    super.viewDidLoad()
    tableView.reloadData()
}
func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    shouldShowEmpty = false
    tableView.reloadData()
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if shouldShowEmpty {
            return 0
        }
        return yourArray.count
    }

这些是没有SELECT store_id as `initial`, CONCAT(',', store_id, ',') AS store_id FROM `mytable` AS `main_table` WHERE (`store_id` LIKE '%,13,%'); 条件的结果:

enter image description here

当我执行查询时,我没有得到任何结果。 where store_id WHERE (的相同内容LIKE '%,3,%');,运算符是某种规则还是例外?

谢谢:)

2 个答案:

答案 0 :(得分:2)

使用FIND_IN_SET解决了我的问题。更多信息: https://www.w3resource.com/mysql/string-functions/mysql-find_in_set-function.php

归功于@Jens

SELECT
  store_id as `store_id`,
FROM `ffm_nonpayment_actiontemplate` AS `main_table`
WHERE FIND_IN_SET('13', store_id);

答案 1 :(得分:0)

问题是WHERE中的字段store_id具有初始值,而不是您使用CONCAT(',', store_id, ',') AS store_id计算的值 如果您想要过滤,可以使用HAVING关键字