表A:
No Brand
1 DELL
2 DELL
3 IBM
4 HP表B:
No Item Des
1 CPU P4
1 Disk 40G
1 CDROM 48X
2 CPU P3
2 Disk 30G
3 CPU P4
3 Disk 40G
4 CPU P4
4 Disk 60G 说明:表A是记录电脑的信息,表B是对应表A电脑的配置信息,从上表知道,编号为1的电脑:品牌是DELL,CPU是P4,硬盘是40G,CDROM是52速的。查询1,查询所有符合CPU为P4的电脑。
查询2,查询所有符合CPU为P4,硬盘为40G的电脑。输出结果为表A的结构,即:
查询1结果:
No Brand
1 DELL
3 IBM
4 HP查询2结果:
No Brand
1 DELL
3 IBM请问:以上的查询1和查询2对应的SQL语句怎么写?
No Brand
1 DELL
2 DELL
3 IBM
4 HP表B:
No Item Des
1 CPU P4
1 Disk 40G
1 CDROM 48X
2 CPU P3
2 Disk 30G
3 CPU P4
3 Disk 40G
4 CPU P4
4 Disk 60G 说明:表A是记录电脑的信息,表B是对应表A电脑的配置信息,从上表知道,编号为1的电脑:品牌是DELL,CPU是P4,硬盘是40G,CDROM是52速的。查询1,查询所有符合CPU为P4的电脑。
查询2,查询所有符合CPU为P4,硬盘为40G的电脑。输出结果为表A的结构,即:
查询1结果:
No Brand
1 DELL
3 IBM
4 HP查询2结果:
No Brand
1 DELL
3 IBM请问:以上的查询1和查询2对应的SQL语句怎么写?
解决方案 »
- AfxGetThread()函数返回空指针是怎么回事?
- 关于字体字模的显示
- 如何判断列是否允许空?
- 如何通过VC中的对话框生成.h的配置文本文件?请进门详看!谢谢!
- 怎样求包含在多边形内的最大矩形?
- ●●●如果用COM传递一个图标?●●●
- 打开技术内幕的配套光盘中的源代码总是出现错误:can not access classview information file.....
- 怪事!一个程序debug时没错,可一旦运行就有stack overflow 的错误?何故啊?
- 请教一下如何对软件进行加密?
- 有没有会啊???????????????????????
- 我用一个CSTRING字符串数组写入文件中,但怎样才能正确的读出他们?高分请教!
- 一个关于数据通讯的傻瓜问题
Where b.Item="CPU" and b.Des="P4" ) bWhere a.no=b.no2. Select A.no,A.Brand from A a,
(Select distinct b.no from B b
Where b.Item="CPU" and b.Des="P4" ) b,
(Select distinct b.no from B b
Where b.Item="Disk" and b.Des="40G" ) cWhere a.no=b.no and a.no=c.no
Where a.no=b.no
Where b.Item="CPU" and b.Des="P4" ) bWhere a.no=b.no2. Select A.no,A.Brand from A a,
(Select distinct b.no from B b
Where b.Item="CPU" and b.Des="P4" ) b,
(Select distinct b.no from B b
Where b.Item="Disk" and b.Des="40G" ) cWhere a.no=b.no and a.no=c.no
后面的那個Where a.no=b.no 是多餘的
以下语句与你的比,哪一个效率高?
select distinct a.no,a.brand
from a,b
where a.no = b.no and
a.no in (select b.no from b
where b.des = 'P4') and
a.no in (select b.no from b
where b.des = '40G')
'p4' and b2.item='disk' and b2.des='40g' and b1.no=b2.no and b1.no = a.no and b2
.no = a.no