SQL 基本语句 表的连接查询

现在书上有两个例题是这样的`
1,查询选学“3-105”课程的成绩高于“109”号学生成绩的所有学生记录并按成绩从高到低进行排列

select x.cno,x.sno,x.degree
from secret x,secret y
where x.cno='3-105'and x.degree>y.degree and y.sno='109' and y.cno='3-105'
order by x.degree desc
2.查询成绩高于学好'109'的课程号"3-105"的成绩的所有记录,并按成绩从低到高排列.

select x.cno,x.sno,x.degree
from score x,score y
where x.degree>y.degree and y.sno='109'and y.cno='3-105'
order by x.degree

这俩题是书上例题。下面没有任何说明,
我想知道选择里面 x.degree>y.degree 是什么意思??
x.cno='3-105'and x.degree>y.degree and y.sno='109' and y.cno='3-105' 啥意思??
看不懂啊

哪位高手发上点类似这样的语句 让我学习下。3Q 好的话追加分

问题一:x.degree>y.degree
x 表和 y 表中有相同的字段 degree, x 中的 degree 值大于 y 中的
问题二:x.cno='3-105'and x.degree>y.degree and y.sno='109' and y.cno='3-105'
x 表中的 cno 字段值为'3-105'
x 表中的 degree 值大于 y 中的 degree 值
y 表中的 sno 字段值为'109'
y 表中的 cno 字段值为'3-105'
以上4个条件取交集
问题三:类似语句
1.
SELECT a.guest_id, a.guest_nme, a.service_type, a.working_addr,
b.phone_num,c.account_id
FROM pcc_tb_guest_mbl a, pcc_tb_guest_num b, pcc_tb_account c
WHERE a.guest_id = b.guest_id
AND b.account_id = c.account_id
AND a.subscr_nme LIKE '王%%'
AND a.service_type = 'voic02'
AND b.phone_num LIKE '8976%'
ORDER BY b.phone_num DESC

2.
SELECT b.phone_num 电话号码,
DECODE (b.num_status, 'A', '可使用', 'V', '保留号','已使用') 状态
FROM (SELECT phone_num, num_status
FROM pcc_tb_nm_number
WHERE MOD (SUBSTR (phone_num, 7), 11) = '0'
AND phone_num LIKE '85%'
AND num_status IN ('A','V') b
WHERE MOD (SUBSTR (b.phone_num, 5, 2), 11) = '0'

第一个你肯定能看懂,第二个写了几个函数DECODE,MOD,SUBSTR
DECODE(字段名,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)
MOD(m,n) 取 m 除以 n 的余数
SUBSTR(字段名,m,n) 字段中从 m 位置开始,取 n 的长度,若 n 省略默认
取到最后
第二句即查询电话号码如 85%xxyy (尾号是双重号),状态是'可使用'和'保留号'的号码

希望对你有所帮助
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-11-10
x.degree>y.degree degree 应该是成绩或者分数吧
也就是说X的分书大于Y的分数,后面的限制条件是 y.sno='109'and y.cno='3-105' 也就是说Y学号是109,查询范围是Y表中的课程号是3-105

x.cno='3-105'and x.degree>y.degree and y.sno='109' and y.cno='3-105'
查询范围是课程号3-105 同时 成绩大于Y的成绩 Y.drgree是学号为109的同学的3-105的成绩
第2个回答  2008-11-10
表的自连接。理论自己看书,翻资料,查网络。
第一题稍微改动下,便于理解
select x.cno,x.sno,x.degree
from secret x,secret y
where x.cno= y.cno --表示自连接的表的关联字段,依靠cno来连接
and x.degree>y.degree --表示别名x表的成绩大于别名y表的成绩
and y.sno='109' --表示别名y表中的109号学生
and x.cno='3-105' --表示3-105的课程
order by x.degree desc --查询的结果成绩按高到低排序
第3个回答  2008-11-10
x.cno='3-105' 选修'3-105' 的学生为x学生
x.degree>y.degree x学生成绩高于y学生
y.sno='109' and y.cno='3-105' y学生为学号109的学生 且选修'3-105'
================================================================