Ⅰ sql语句12道题谢谢谢啦
如果表MZRZB中不存在字段iJHBS,则修改表,增加字段。
if not exists ( 。。。) 是用来判断的,如果为真,则执行后续的语句。
select b.* from sysobjects a join syscolumns b on a.id = b.id where a.name ='MZRZB' and b.name = 'iJHBS' 是根据系统视图,获取指定表的指定字段名的数据行。
alter table MZRZB add iJHBS INT null 修改表,增加一个字段。
Ⅱ SQL语句题目
(5)A
(6)B
1.create index IDX_Readers_1 on Readers(Rname asc);
create index IDX_Books_1 on Books(Btitle desc)
4,5不知道表结构及表之间的主键外键关系就不写了
6.insert into readers(id,name,type) values ('200406002','路宏','2');
任务2:查询总量select count(1) from books;(如果books表无重复记录)
group by 出版社即可按出版社分组;
任务三:不知道表结构就不写sql了
Ⅲ sql语句 面试题
A.创建表格CODE省略
注明:学生表PK stu_id 课程表pk cos_id 分数表PK enrollment_id FK stu_id,cos_id
B.插入数据code省略
C.Query
select s.stu_id,stu_name,count(cos_id) from student s,enrollments e where s.stu_id = e.stu_id and e.grade>60 group by s.stu_id,stu_name;
select e.stu_id,s.stu_name,c.cos_name from student s,enrollments e,course c
where s.stu_id = e.stu_id
and e.cos_id = c.cos_id
and c.cos_name = 'CHINESE'
and s.stu_name like 'W%';
select stu_id,stu_name from (select e.stu_id,stu_name,cos_name from enrollments e,student s,course c
where s.stu_id = e.stu_id
and e.cos_id = c.cos_id
and c.cos_name IN ('CHINESE','MUSIC'))
group by stu_id,stu_name
having count(cos_name) = 2
select distinct e.cos_id,c.cos_name,count(e.stu_id) stu_count,count(e.stu_id)-NVL(A.FAIL,0) upscore,(count(e.stu_id)-NVL(A.FAIL,0))/count(e.stu_id) rate from
(select cos_id,count(stu_id) fail from enrollments where grade<60 group by cos_id) a,enrollments e,course c
where e.cos_id = a.cos_id(+)
and e.cos_id = c.cos_id
group by e.cos_id,NVL(a.fail,0),c.cos_name;
update student
set avg_grade =(select avg(grade) X from enrollments group by stu_id
having student.stu_id = enrollments.stu_id);
select stu_id,avg(grade) from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments)
group by stu_id
having count(*)<=2
UNION
select A.stu_id,avg(A.grade)from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments) A,
(select stu_id,count(*) c from
(select stu_id,cos_id,grade,row_number() over(partition by stu_id order by grade ) X from enrollments)
group by stu_id) B
where A.stu_id = B.stu_id
and A.x>1 and x<B.c
group by A.stu_id,b.c
_________________________________________________
环境:oracle 10g/TOAD 以上代码均通过测试,如有问题,请联系,谢谢
Ⅳ 问一道SQL语句的题目,请各位帮帮忙。
1,select 任课教师 ,开课系
from 课程表
where 任课教师 =‘李老师’
2,select 学生表.学号 ,学生表.姓名
from 学生表,学习表, 课程表
where 学生表.学号= 学习表.学号
and 学生表.年龄 >=19
and 学生表.性别 = ‘女’
and 学生表.所在系= ‘计算机’
3,select 学生表.姓名
from 学生表,学习表, 课程表
where 学生表.学号= 学习表.学号
and 课程表.课程号 = 学习表.课程号
and 学生表.性别 = ‘女’
and 课程表.课程号 not in (select 课程号
from 课程表
where 任课教师 =‘刘老师’)
4,select 课程表.课程号,课程表.开课系
from 学生表,学习表, 课程表
where 学生表.学号= 学习表.学号
and 课程表.课程号 = 学习表.课程号
and 学生表.姓名 = ‘王乐’
5,select 学生表.学号,学生表.姓名
from 学生表
where 学生表.学号 in (select 学生表.学号,count(学号) as 修读门数
from 学习表
group by 学习表.学号
having 修读门数>=3)
6,select count(*) from((select 学生表.姓名
from 学生表
where not exists
(select 课程好
from 课程表
where not exists
(select *
from 学习表,学生表,课程表
where 学习表.学号= 学生表.学号
and 学习表.课程号= 课程.课程号))
7,select count(学生表.学号)
from 学生表
where 学生表.所在系= ‘计算机’
8,select 课程表.课程号,课程表.课程名,avg(学习表.成绩)
from 学生表,学习表, 课程表
where 学生表.学号= 学习表.学号
and 课程表.课程号 = 学习表.课程号
and 课程表.课程系 = ‘计算机’
group by 课程表.课程号,课程表.课程名
9,select 学生表.学号,学生表.所在系
from 学生表,
where 学生表.姓名 like ‘张%’
and 学生表.姓别 = ‘男’
10 update 学习表
set 学习表.成绩=null
where 课程表.课程号 = 学习表.课程号
and 课程表.课程名 = ‘数据库原理课’
and 学习表.成绩 <='69'
以上答案请你参考,由于时间原因,有不准确的请你谅解
Ⅳ SQL题 根据题目要求写出对应的SQL语句
您好,你的问题,我之前好像也遇到过,以下是我原来的解决思路和方法,希望能帮助到你,若有错误,还望见谅!--1、出版过计算机类图书的出版社编号(去掉重复行)select distinct CNO from Bwhere TCATEGORY='计算机'--2、南开大学出版社出版的“经济”类或“数学”类图书的信息select * from Bwhere TCATEGORY in('经济','数学') and CNO in (select CNO from C where CNAME='南开大学出版社')--3、编号“00001”的出版社出版图书的平均价格select avg(TPRICE) from B where CNO='00001' --4、至少出版过20套图书的出版社编号、出版社名称、出版图书套数 按出版社编号升序排列select B.CNO,CNAME,count(B.CNO)as [出版图书套数]from B ,Cwhere B.CNO=C.CNOgroup by B.CNO,CNAMEhaving count(*)>=20--5、比编号“00001”出版图书套数多的出版社编号select CNO from B group by CNO having count(*)>(select count(*) from B where CNO='00001'),非常感谢您的耐心观看,如有帮助请采纳,祝生活愉快!谢谢!
Ⅵ sql 语句问题,考试题目。大虾帮忙啊
--)
用SQL语句建立P表。
USE
[SPJ]
GO
/******
Object:
Table
[dbo].[P]
******/
SET
ANSI_NULLS
ON
GO
SET
QUOTED_IDENTIFIER
ON
GO
IF
EXISTS(SELECT
*
FROM
SYSOBJECTS
WHERE
NAME
=
'P')
DROP
TABLE
P
GO
CREATE
TABLE
[dbo].[P](
[PNO]
[nvarchar](50)
NOT
NULL,
[PNAME]
[nvarchar](50)
NOT
NULL,
[COLOR]
[nvarchar](50)
NOT
NULL,
[WEIGHT]
[int]
NOT
NULL
)
GO
--2)用SQL语句找出所有零件的名称、颜色、重量。
SELECT
PNAME,COLOR,WEIGHT
FROM
P
--3)用SQL语句把全部红色零件的颜色改为黄色。
UPDATE
P
SET
COLOR
=
'YELLOW'
WEHRE
COLOR
=
'RED'
--4)
用SQL语句由S5供给J4的零件P6改为由S3供应。
UPDATE
SPJ
SET
SNO
=
'S3'
WEHRE
PNO
=
'P6'
AND
JNO
=
'J4'
AND
SNO
=
'S5'
Ⅶ 数据库中SQL数据题目
1:select *职工号 from 工作关系 where "公司号=C2" AND "公司号=C5"
2:UPDATE 工作关系
SET工资 = 工资 * 1.05
WHERE公司号IN
(SELECT公司号
FROM 公司关系
WHERE公司名 =‘联华公司’
还有一题啊》??给我加分哦。
3、SELECT 作者名,书名,出版社
FROM 图书,作者
WHERE 图书 . 作者编号 = 作者 . 作者编号
AND 年龄 < = (SELECT AVG (年龄)
FROM 作者)
同学,这些是数据库里面的最基本知识。你只要用心去学习就肯定会的。SQL语句里面也就SELECT,INSERT,DELETE,UPDATE等基本语句的
Ⅷ 关于SQL语句的选择题!
比如学生A,同时选修了C01和C02,这时候SELECT * FROM SC WHERE SC.S# = S.S# AND C# <>'C02'返回的是true,因为有一条记录C#是C01。也就是说,学生A尽管选修了C02,也会被查找到。