MySQL使用条件查询需要注意的问题
1.查询时若字段名含有":",则会查询异常
数据库
CREATE TABLE `new_table` (
`单价:元` int(11) DEFAULT NULL,
`数量` int(11) DEFAULT NULL
)
select * from test.new_table where 单价:元=100;
SQL语法错误:···for the right syntax to use near ':元=100' at line 1
2.查询时若字段名含有"()",则会查询异常
数据库
CREATE TABLE `new_table` (
`单价(元)` int(11) DEFAULT NULL,
`数量` int(11) DEFAULT NULL
)
select * from test.new_table where 单价(元)=100;
查询异常1:Error Code: 1305. FUNCTION test.单价 does not exist
查询异常2:Error Code: 1046. No database selected Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar.
3.查询时若字段名不含有"()",也不含有":",查询正常
SELECT * FROM test.new_table where 数量 = 100;