如何使用像sqlite中的复杂查询的运算符 [英] how to use like operator for complex query in sqlite

查看:136
本文介绍了如何使用像sqlite中的复杂查询的运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在SQLite数据库中有一个名为student的表。

Hi all i have the following table called student in SQLite database.

这是我的表结构

id       name
-----------------------

"3"  "Babu Qw"  
"2"  "Ganesh Babu"  
"1"  "Murali  Abb"  
"4"  "ganesh1 Babu"             
"5"  "hari murali"              
"10" "Abbash abc"   

name字段由名字和姓氏组合。例如Babu QwBabu是名字,Qw是用空格分隔的最后一个名字。

name field is combined by first name and last name. for example "Babu Qw" Babu is the first name and Qw is the last name its separated by a space.

,name是输入字段,其中ba输入参数( Ex .. name like'ba'

and name is the input field where 'ba' is my input parameter.(Ex .. name like 'ba')

现在我想获取任何名称

now i want to fetch the records whatever name (first name or last name ) starts with 'ba' not by any middle character.

输出将是:

id       name
-----------------------

"3"  "Babu Qw"  
"2"  "Ganesh Babu"  
"4"  "ganesh1 Babu" 

这里Abbash abc(名字Abbash或姓abc不以ba开头),因此Abbash abc未列出。

here "Abbash abc" (first name Abbash or last name abc does not starts with ba) so that "Abbash abc" not listed.

推荐答案

这应该做的诀窍:

select id, name
from table
where name like 'Ba%' or name like '% Ba%'

这篇关于如何使用像sqlite中的复杂查询的运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆