查询

Code   Name Age  Class   Score 

97001 张三   22    数学     80  

97002 赵四   21    计算机  59  

97003 张飞   20    计算机  60  

97004 李五   22    数学     55 


1、请写出SQL,找出所有姓张的学生,并按年龄从小到大排列;

select * from TableX where name like '张%' order by age  


2、请写出SQL,取出计算机科考成绩不及格的学生;

 
select * from tableX where code in (select code from tableY WEHRE class='计算机' and score <60)

 1 create database mydata;
 2 use mydata;
 3 drop table tablex;
 4 create table tablex(
 5 code int,
 6 name varchar(100),
 7 age int,
 8 class varchar(100),
 9 score int
10 );
11 insert into tablex values(97001, 'zhangsan', 22, 'shuxue', 80);
12 insert into tablex values(97002, 'zhaosi', 21, 'jisuanji', 59);
13 insert into tablex values(97003, 'zhangfei', 20, 'jisuanji', 60);
14 insert into tablex values(97004, 'liwu', 22, 'shuxue', 55);
15 
16 select * from tablex;
17 select * from tablex where name like 'zhang%' order by age;
18 select * from tablex where code in 
19 (select code from tablex where class='jisuanji' and score <60);
20 (select code from tablex where class='jisuanji');

 

posted @ 2014-10-21 22:31  soul390  阅读(419)  评论(0编辑  收藏  举报