再问个sql语句

来源:百度知道 编辑:UC知道 时间:2024/06/08 17:52:47
请写出在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倒排序
注:因为两个表中的字段没有重名,因此写本条SQL语句字段名不用

加表名

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

如果是Access数据库,要把substring改成mid

select c_name,s_no,s_name from class
inner join stu
on class.c_id=stu.s_cid
where c_stu<20 and s_no like'_006%'
order by s_no desc

11