求2题SQL题目的答案,考试就考你了

来源:百度知道 编辑:UC知道 时间:2024/06/24 23:05:00
根据条件写SQL语句
商品表1(商品代号 char(8) , 分类号 char(8) 单价float 数量 int)
商品表2(商品代号 char(8) , 产地char(8) 品牌 (8) ) 两张表
1从商品库中查出数量在10-20之间的商品种数
2从商品库中查出每类(既分类名相同)商品的总数量
3从商品库中查出比所有商品单价的平均值要低的全部商品
4从商品库中查出所有商品的不同产地的总数
根据条件写SQL语句
学生(学号char(8),姓名char(8),性别char(2) 系名char(20),出生年月 date time)
选课(学号char(8) 课程号char(10) 成绩(int))
课程 (课程号char(8) 课程学分(int) )
1从教学库中查询出每门课程被选修的学生数
2从教学库中查询出所有已被学生选修的课程
3查找学生表中电子工程系的学生姓名,系名和出生年月,结果按出生年月降叙排列,年龄既从小到大排列
4查找姓名以”李”打头的所有学生名
5从教学库中查出所有学生的选课情况,要求没有选择任何课程的学生信息也反映出来
(提示此查询需要使用左连接,学生为左,选课为右)
6在课程表里插入一个元组数据(“A0074”,”大学英语(1),4”)

create table table1
(
prodCode char(8) primary key ,
prodType char(8) not null,
prodPrice float not null,
prodCount int not null
)
create table table2
(
prodCode char(8) not null,
prodAddress char(8) not null,
prodBrand char(8)
)

//条件1
select count( prodCode) from table1 where prodCount like '[1-2]%'

select count( prodCode) from table1 where prodCount between 10 and 20
//条件2
select count( prodCode),prodType from table1 group by prodType
// 条件3
select count( prodCode) from table1 where prodPrice < (select avg(prodPrice) from table1)
// 条件4
select count(distinct prodAddress) from table1

create table student
(
studCode char(8) primary key,
studName char(8) not null,
studSex char(2),
studFaculty char(20) ,
studBirthday datetime
)
create table course_ch
(
studCode char(8) ,
courseCode