MySQL动态生成多个where子句
因此,用户可以选择要按多少类别筛选列表 当只选择一个项目时,一切正常:MySQL动态生成多个where子句,mysql,sql,where,Mysql,Sql,Where,因此,用户可以选择要按多少类别筛选列表 当只选择一个项目时,一切正常: SELECT SQL_CALC_FOUND_ROWS a.id, a.PAnr, b.family, b.articlenr, b.ratio, a.oiltype, a.oiltemp FROM testdata_test a, testdata_gear b WHERE a.id = b.test_id AND b.family = 'R660' ORD
SELECT SQL_CALC_FOUND_ROWS a.id, a.PAnr, b.family, b.articlenr, b.ratio, a.oiltype, a.oiltemp
FROM testdata_test a, testdata_gear b
WHERE a.id = b.test_id AND b.family = 'R660'
ORDER BY a.PAnr desc
LIMIT 0, 10
但当用户添加更多时:
SELECT SQL_CALC_FOUND_ROWS a.id, a.PAnr, b.family, b.articlenr, b.ratio, a.oiltype, a.oiltemp
FROM testdata_test a, testdata_gear b
WHERE a.id = b.test_id AND b.family = 'R540' OR b.family = 'R660'
ORDER BY a.PAnr desc
LIMIT 0, 10
我得到了大约400万次点击,而没有和部分的表大约是4000次。如果用户选择另一个,点击率约为800万次。
我遗漏了什么?您混合了
和以及或子句,没有()
,因此您有效地运行了:
WHERE ((a.id = b.test_id) AND (b.family = 'R540'))
OR (b.family = 'R660')
注意()
是如何定位的
你可能想要
WHERE (a.id = b.test_id) AND (b.family IN ('R540', 'R660'))
您混合了和以及或子句,而没有()
,因此您有效地运行了:
WHERE ((a.id = b.test_id) AND (b.family = 'R540'))
OR (b.family = 'R660')
注意()
是如何定位的
你可能想要
WHERE (a.id = b.test_id) AND (b.family IN ('R540', 'R660'))
您混合了和以及或子句,而没有()
,因此您有效地运行了:
WHERE ((a.id = b.test_id) AND (b.family = 'R540'))
OR (b.family = 'R660')
注意()
是如何定位的
你可能想要
WHERE (a.id = b.test_id) AND (b.family IN ('R540', 'R660'))
您混合了和以及或子句,而没有()
,因此您有效地运行了:
WHERE ((a.id = b.test_id) AND (b.family = 'R540'))
OR (b.family = 'R660')
注意()
是如何定位的
你可能想要
WHERE (a.id = b.test_id) AND (b.family IN ('R540', 'R660'))
将查询更改为此,查询将不会按预期运行或语句
SELECT SQL_CALC_FOUND_ROWS a.id, a.PAnr, b.family, b.articlenr,
b.ratio, a.oiltype, a.oiltemp
FROM testdata_test a, testdata_gear b
WHERE a.id = b.test_id AND (b.family = 'R540' OR b.family = 'R660')
ORDER BY a.PAnr desc
LIMIT 0, 10
或
将查询更改为此,查询将不会按预期运行或语句
SELECT SQL_CALC_FOUND_ROWS a.id, a.PAnr, b.family, b.articlenr,
b.ratio, a.oiltype, a.oiltemp
FROM testdata_test a, testdata_gear b
WHERE a.id = b.test_id AND (b.family = 'R540' OR b.family = 'R660')
ORDER BY a.PAnr desc
LIMIT 0, 10
或
将查询更改为此,查询将不会按预期运行或语句
SELECT SQL_CALC_FOUND_ROWS a.id, a.PAnr, b.family, b.articlenr,
b.ratio, a.oiltype, a.oiltemp
FROM testdata_test a, testdata_gear b
WHERE a.id = b.test_id AND (b.family = 'R540' OR b.family = 'R660')
ORDER BY a.PAnr desc
LIMIT 0, 10
或
将查询更改为此,查询将不会按预期运行或语句
SELECT SQL_CALC_FOUND_ROWS a.id, a.PAnr, b.family, b.articlenr,
b.ratio, a.oiltype, a.oiltemp
FROM testdata_test a, testdata_gear b
WHERE a.id = b.test_id AND (b.family = 'R540' OR b.family = 'R660')
ORDER BY a.PAnr desc
LIMIT 0, 10
或
你错过了什么?括号。是的,差不多是@Danbracuk你错过了什么?括号。是的,差不多是@Danbracuk你错过了什么?括号。是的,差不多是@Danbracuk你错过了什么?括号。是的,差不多是在DanBracuk