| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 619 人关注过本帖
标题:[多表查询]--求助
只看楼主 加入收藏
landigital
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-9-22
收藏
 问题点数:0 回复次数:3 
[多表查询]--求助

请写出在class和stu表中查找满足如下条件的记录的sql语句:
1)表class中的字段c_id与stu表中的s_cid为关联字段
2)返回字段 c_name,s_no,s_name
3)查询条件 c_stu 字段值大于20,并且s_no第二到四位是"006"这三个字符
4)查询结果按s_no倒排序

谢了~~~~~

搜索更多相关主题的帖子: 查询 
2006-09-22 21:43
LouisXIV
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:789
专家分:0
注 册:2006-1-5
收藏
得分:0 
--test it by yourself please

select c.c_name,s.s_no,s.s_name
from class c inner join stu s
on c.c_id=s.s_cid
where c_stu>20 and substring(rtrim(s_no),2,4)='006'
order by s_no desc

2006-09-22 22:19
landigital
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-9-22
收藏
得分:0 
以下是引用LouisXIV在2006-9-22 22:19:38的发言:
--test it by yourself please

select c.c_name,s.s_no,s.s_name
from class c inner join stu s
on c.c_id=s.s_cid
where c_stu>20 and substring(rtrim(s_no),2,4)='006'
order by s_no desc

where c_stu>20 and s_no like '_006%'
order by s_no desc
使用模糊查询的关键字like~~~

2006-09-22 22:57
fengmumei
Rank: 2
等 级:论坛游民
威 望:2
帖 子:298
专家分:14
注 册:2006-9-16
收藏
得分:0 
select class.c_name,stu.s_no,stu.s_name from class,stu
where class.c_id=stu.s_cid and class.c_stu>20 and stu.s_no like '_006%'
order by stu.s_no desc

首先,不知道你的那两个表里的字段是否相同,所以我把表名都加上了,若是字段不相同,你可把表名去掉
select c_name,s_no,s_name from class,stu
where c_id=s_cid and c_stu>20 and s_no like '_006%'
order by s_no desc
再者,不知道你的字段s_no是几位,所以要用like '_006%'


随缘不变,不变随缘
2006-09-27 11:14
快速回复:[多表查询]--求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012707 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved