2015-06-08 54 views
0

我有搜索查询“AA BB”,也有在表“AA BB CC”行。所以我的SQL查询应该返回该行。这是我该怎么办:SQLite的例外

select * from company 
    where 
     (ASCII_NAME like %'aa'% 
     and ASCII_NAME like %'bb'%) 
    and CITY_ID=0 and parent=-1; 

但我的日志说:

android.database.sqlite.SQLiteException:近 “%”:语法错误(代码 1),而编译:选择*从公司那里(ASCII_NAME像 % 'AA' %和ASCII_NAME喜欢% 'BB' %)和 CITY_ID = 0和家长= -1

有什么不对?

回答

1

你的语法是错误的

select * from company 
    where 
     (ASCII_NAME like '%aa%' 
     and ASCII_NAME like '%bb%') 
    and CITY_ID=0 and parent=-1; 
1

包括在单引号%的迹象。 像:

select emp_name from employee where emp_name like '%s%';