日期:2014-05-20  浏览次数:20604 次

新手 SQL 查询语句求助
 
  请输入查询关键字:_______________ 查询
  里面输入学号 或者 姓名 或者 班级 都能查到 的 数据库查询语句 


------解决方案--------------------
select * from AAA where (学号 like '%输入值%') or (姓名 like '%输入值%') or (班级 like '%输入值%') ;
------解决方案--------------------
补充下 表 :student
列名: stuID ,stuName,class
输入的字:String name=this.jtf1.getText().trim();


String sql = "select * from student where (stuID = " + name + " ) or ( stuName like '% " + 
name +"%') or (class like '%" + name "%') " ;
------解决方案--------------------
SQL code

if not object_id('tempdb..#Student') is null
begin
drop table #Student
end
create table #Student(stu_id nvarchar(36),stu_name nvarchar(36),stu_class nvarchar(36))
insert into #Student
select '1','a','b' union all
select '2','b','b' union all
select '3','c','b' union all
select '4','d','c' union all
select '5','e','d' 


select * from #Student where stu_id='c' or stu_name='c' or stu_class='c'

/*
3    c    b
4    d    c
*/

------解决方案--------------------
如果是模糊查询,就用各个字段 like '%输入的信息%',然后or各个条件就可以了
如果是精确查询,就用各个字段 = '输入信息',然后or各个条件
for example
SQL code

--模糊查询
select * from student   
 where stuID like '%' || your_text || '%'
    or stuName like '%' || your_text || '%'
    or [class] like '%' || your_text || '%'

--精确查询
select * from student   
 where stuID = your_text
    or stuName = your_text
    or [class] = your_text