日期:2014-05-16  浏览次数:20501 次

android 数据库操作 插入彩信,数据库子查询
插入一条短信:
insert into pdu values(1,'1','1989-2-2','1','1','1','1','1','1','1','1','1','1','1');

插入一条彩信:
insert into pdu
values(1,11,'1989-2-2','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1');
insert into part
values(101,1,'1','1','1','1','1','1','1','1','1','1','1','1');

内连接查询:
select u.*,t.* from pdu u ,part t where u._id=t.mid;


子查询:
有这么个题目
求至少选修了 学号为s2的学生所选修的全部课程 的学生学号和姓名.

s是学生表 sc是选课表

老师教的方法是

select sno,sname
form s
where not exists
(select * from sc as sc1
where sc1.sno='s2'
and not exists
(select * from sc as sc2
where s.sno=sc2.sno
and sc2.cno=sc1.cno) )

-----------------------
以下是我写的代码:
select * from s where sno in
(
select sno from sc a
join
(select cno from sc where sno='s2') b
on a.cno=b.cno
group by sno
having count(*)=(select count(*) from sc where sno='s2')
)
我的思路是这样的,如果学生s1选的课程包含学生s2选的所有课程,那么这两个学生的课程inner join之后,结果集的记录数应该等于s2的选课数.根据这个规则,就可以通过以下代码求出学号:
select sno from sc a
join
(select cno from sc where sno='s2') b
on a.cno=b.cno
group by sno
having count(*)=(select count(*) from sc where sno='s2')
学号出来了,对应的名字也就不难求了,如第一段代码.