我有搜索查询" aa bb"而且还有" aa bb cc"在表中的行。所以我的SQL查询应该返回该行。这就是我的方式:
select * from company
where
(ASCII_NAME like %'aa'%
and ASCII_NAME like %'bb'%)
and CITY_ID=0 and parent=-1;
但我的日志说:
android.database.sqlite.SQLiteException:near"%":语法错误(代码 1):,编译时:select * from company where(ASCII_NAME喜欢 %' aa'%和ASCII_NAME喜欢%' bb'%)和 CITY_ID = 0且parent = -1
有什么问题?
答案 0 :(得分:1)
您的语法错误
select * from company
where
(ASCII_NAME like '%aa%'
and ASCII_NAME like '%bb%')
and CITY_ID=0 and parent=-1;
答案 1 :(得分:1)
在单引号中包含%符号。 像:
select emp_name from employee where emp_name like '%s%';