在MySQL语句中返回\'

时间:2014-09-08 19:34:04

标签: php mysql

我在MySQL中存储的数据如下所示:

q1
People\'s
People\'s
People\'s

我试图写一个MySQL语句来返回这些但是它会导致我一个问题的计数,我尝试了以下所有但是无济于事:

SELECT * AS Total,
(SELECT COUNT(q1) FROM results WHERE q1 = 'People\'s') AS Count_Q1
FROM results

SELECT * AS Total,
(SELECT COUNT(q1) FROM results WHERE q1 = 'People'\'s')
FROM results

SELECT * AS Total,
(SELECT COUNT(q1) FROM results WHERE q1 = 'People''\'s')
FROM results

有人能找到我错的地方吗?

2 个答案:

答案 0 :(得分:3)

应该是:

SELECT *,
(SELECT COUNT(q1) FROM results WHERE q1 = 'People\\\'s') AS Total
FROM results

上述内容正好来自MySQL Documentation

enter image description here

SQL Fiddle演示显示它确实有效。

答案 1 :(得分:0)

  

选择*为总计,(从结果中选择计数(q1),其中q1 ='人们从结果中选择

它适用于你