当前位置:首页 » 编程语言 » 笔试题sql

笔试题sql

发布时间: 2022-05-21 22:11:55

sql数据库面试题 急急急

a)select pname as '商品名',avg(qty) as 平均销售量 from s,p,m where m.city='上海' and s.mno=m.mno and p.pno=s.pno,select p.Pno,p.pname,sum(s.qty)
from s left join p on s.pno=p.pno left join m on p.Mno=m.Mno
where m.city='上海市'
group by p.Pno,p.pname,p.city,p.color
b)、先删除Sale表的外键PNO,再删除gds表。

c)联系:视图(view)是在基本表之上建立的表,它的结构(即所定义的列)和内容(即所有数据行)都来自基本表,它依据基本表存在而存在。一个视图可以对应一个基本表,也可以对应多个基本表。视图是基本表的抽象和在逻辑意义上建立的新关系
区别:1、视图是已经编译好的sql语句。而表不是
2、视图没有实际的物理记录。而表有。
3、表是内容,视图是窗口
4、表只用物理空间而视图不占用物理空间,视图只是逻辑概念的存在,表可以及时四对它进行修改,但视图只能有创建的语句来修改
5、表是内模式,视图是外模式
6、视图是查看数据表的一种方法,可以查询数据表中某些字段构成的数据,只是一些SQL语句的集合。从安全的角度说,视图可以不给用户接触数据表,从而不知道表结构。
7、表属于全局模式中的表,是实表;视图属于局部模式的表,是虚表。
8、视图的建立和删除只影响视图本身,不影响对应的基本表。

❷ 面试题目(sql)

1、忍不住想说一句,因为第一题中的字段类型是
【日期型】,而各种数据库操作日期型数据有不同的方法,没有一种共通的方法,所以脱离了数据库而言没有一种共通的sql。
2、select
ID,NAME,ADDRESS,PHONE,LOGDATE
from
T
where
ID
in(
select
ID
from
T
group
by
NAME
having
count(*)>1)
order
by
NAME;
3、delete
from
T
where
ID
not
in
(select
min(id)
from
T
group
by
name);
4、update
T
set
T.ADDRESS=(select
E.ADDRESS
from
E
where
E.NAME=T.NAME),
T.PHONE=(select
E.PHONE
from
E
where
E.NAME=T.NAME);
5、这个不同的数据库也有不同的处理方法,不能脱离数据库谈了。
如:SqlServer或者access可以使用
top
oracle可以使用
rownum

---
以上,希望对你有所帮助。

❸ SQL笔试题


一般不用一句话写
数据部分 select date, sum(num) as num from table group by date
合计部分 select sum(num) as sum from table
如果非要和在一起显示只能这样
select date, sum(num) as num from table group by date
union
selec '合计' as date, sum(num) as num from table


假设你的月份是数字的话
select t1.person, t1.month, t1.income as 本月收入, t2.income as 上月收入, t2.income as 下月收入 from table t1 inner join table t2 on t1.month=t2.month+1 inner and t1.person=t2.person inner join table t3 on t1.month=t3.month-1 and t1.person=t3.person

假设月份是日期格式(yyyy-mm-dd)
select t1.person, t1.month, t1.income as 本月收入, t2.income as 上月收入, t2.income as 下月收入 from table t1 inner join table t2 on datediff(m,t2.month,t1.month)=1 inner and t1.person=t2.person inner join table t3 on datediff(m,t1.month,t3.month)=1 and t1.person=t3.person

如果能给出月份的实际数据会比较好给你个准确的答案

❹ sql笔试题,帮帮小弟!

二个我都有在我的电脑上测试,都是可以的,请参考。

第一题的答案
SELECT a, COUNT(*)
FROM (SELECT a = CASE WHEN score >= 0 AND
score < 10 THEN '0-9' WHEN score >= 10 AND
score < 20 THEN '10-19' WHEN score >= 20 AND
score < 30 THEN '20-29' WHEN score >= 30 AND
score < 40 THEN '30-39' WHEN score >= 40 AND
score < 50 THEN '40-49' WHEN score >= 50 AND
score < 60 THEN '50-59' WHEN score >= 60 AND
score < 70 THEN '60-69' WHEN score >= 70 AND
score < 80 THEN '70-79' WHEN score >= 80 AND
score < 90 THEN '80-89' WHEN score >= 90 AND
score < 100 THEN '90-99' ELSE '100' END
FROM student) a
GROUP BY a

第二题的答案
SELECT TOP 10 ip, countip
FROM (SELECT ip, COUNT(*) AS countip
FROM records
GROUP BY ip) a
ORDER BY countip DESC

❺ sql笔试题,写出这个sql

此题的考点是行转列,可用case when +group by 实现

具体如下

select

s.userid,

max(case when s.typeid=1 then s.vaule END) 手机号码,

max(case when s.typeid=2 then s.vaule END) 邮箱地址,

max(case when s.typeid=3 then s.vaule END) 固定号码,

max(case when s.typeid=4 then s.vaule END) 微博名字

from (select a.userid,b.typeid,b.typename,a.vaule from test.messge a,test.baseon b

where a.typeid=b.typeid)s

GROUP BY s.userid

❻ SQL笔试题寻求答案

select count(*) ,case Fwage > 5000 then 1 else 0 end as type1, case fage > 32 then 1 else 0 end as type2 from emploreeinfo group by type1,type2

有个问题啊 就是你的month是什么形式的 年月日 还是数字形式 我按数字形式给你写一个啊 如果是年-月的话 回头再给你写
我假设是同一年了 如果不是可以在left join 的on后面改条件
select s1.month,sum(s1.consume) as 当月消费, sum(s2.consume) as 上月消费, sum(s3.consume) as 下月消费, from student s1 left join student s2 on s1.month=s2.month+1 left join student s3 on s1.month=s3.month-1 group by s1.month

❼ SQL数据库笔试题

1 前面加createview 视图名 as 2 sele 学号 from 学生表 where 学号 in(sele max(成绩) from 成绩) group by 学号3 类似

❽ sql语句 面试题

这个简单,看答案,采纳吧~
第一题是,用双top结构就可以查出来
1,select * from 学生表 where 学号 in
(select top 5 学号 from 成绩表 where 学号 not in(select top 10 学号 from 成绩表 order by 分数) order by 分数)

第二题是比较简单,用复合函数就行了,having
select 姓名 from 成绩表 group by 姓名 having avg(分数)>80
采纳吧~

❾ sql笔试题三表联查求解

select sum (m.order_price) from (select * from sellorders m ,(select * from branch b, storehouse n where b.branch_id = n.branch_id)t where m.store_id = t.store_id and m.delivery_state = 15 and (m.order_price>500) and (date(m.order_time) between '2015-03-01' and '2015-03-31') and b.branch_id = ?)
传个分公司ID参数就能查到这个公司的了。

❿ sql笔试题

两个表第一个store(store_id,city,space)
第二个employee(store_id,emp_id,salary)
1、每家店的平均工资
select t1.store_id,AVG(salary) from store t1 inner join employee t2 on t1.store_id=t2.store_di
group by t1.store_id

2、每个城市的平均工资
select t1.city,AVG(salary) from store t1 inner join employee t2 on t1.store_id=t2.store_di
group by t1.city
3、查找该城市存在员工工资低于1000的城市信息
select distinct t1.city
from store t1 inner join employee t2 on t1.store_id=t2.store_id
where t2.salary<1000

4、查找城市其职工工资有低于1000的该城市职工平均工资
select t1.city,avg(t2.salary)
from store t1 inner join employee t2 on t1.store_id=t2.store_id
where exists(select * from employee t3
where t1.store_id=t3.store_id and t3.salary<1000)
group by t1.city

其他的自己看吧,比较简单
5、每个城市工资最高的员工信息
select t2.city,t1.* from employee t1 inner join store t2 on t1.store_id=t2.store_id
where exists(
select * from (
select t1.city,max(salary) from store t1 inner join employee t2 on t1.store_id=t2.store_di
group by t1.city) tt where t1.city=tt.city and t2.salary=tt.salary)
6、查询每个城市的员工总工资,总的店面面积(?),门店的数量,员工数量,最高/最低工资数

热点内容
pid算法调速 发布:2025-02-13 21:20:31 浏览:686
脚本中new 发布:2025-02-13 21:00:11 浏览:741
什么配置的笔记本电脑能玩神武 发布:2025-02-13 20:54:40 浏览:178
挑选云服务器需要注意什么 发布:2025-02-13 20:53:31 浏览:98
加密滴胶卡 发布:2025-02-13 20:30:48 浏览:275
javalogin 发布:2025-02-13 20:25:48 浏览:427
智联招聘无法上传照片 发布:2025-02-13 20:16:03 浏览:529
python元素替换list 发布:2025-02-13 20:03:48 浏览:773
windows系统账户名和密码是多少 发布:2025-02-13 20:03:02 浏览:531
我的世界带有商店服务器好吗 发布:2025-02-13 20:02:50 浏览:616