高分悬赏几道计算机SQL数据库的题!做出来了先支付100分,要是满意的话,在加赏50~

高分悬赏几道计算机SQL数据库的题!做出来了先支付100分,要是满意的话,在加赏50~,第1张

1. 查询雇员(employee)的姓和名

Select substring(username,1,1) as 姓 from employee

Select substring(username,2,2) as 名 from employee

2. 查询雇员的姓名

Select username from employee

3. 查询雇员数

Select count(*) from employee

4. 查询雇员的姓名和职务

Select username,,duty from employee

5. 查询雇员的工龄

Select year(getdate())-开始工作日期 as 工龄 from employee

任务2:条件查询

1. 查询雇员(employee)从事"Sales Representative"职务的有哪些人

Select * from employee where duty=’ Sales Representative’

2. 查询工龄超过15年的雇员

Select * from employee where cast( (year(getdate())-开始工作日期) as int)>=15

3. 查询姓以a开头的雇员

Select * from employee where username like ‘a%’

4. 查询姓的开头字母在m以后的雇员

Select * from employee where cast((substring(username,1,1) as varchar)>=’m’

5. 认为hire_date是雇员生日,查询巨蟹座的雇员

Select * from employee where birthday between ‘6-22 ‘ and ‘7-22’

任务3:联合查询

1. 查询雇员和雇员职位

Select a.id,b.duty from employee, as a,jobs as b

2. 查询雇员、雇员职位和雇员所在出版社

Select a.id,b.duty, b.publishing from employee as a,jobs as b on a.id=b.id

3. 查询雇员、雇员工资、雇员离本职位最高工资的差值

select a. ID,a.username,a.[雇员工资],b.[最高工资]-a.[雇员工资] as [差值] from employee a,jobs b where a.[职位]=b.[职位]

都是用SQL SERVER的语法来做的。不知道你要求的是哪个数据库的语法。

第一题:

---t表查询每次运输和下次的时间间隔,同一辆车,两次货运日期之间没有运输记录,就连续两次

select top 1 t1.货车编号, 姓名,联系方式

FROM

(select top 2 货车编号,最长间隔 from

(select a.货车编号, max(datediff(d,a.运输日期,b.运输日期) ) as 最长间隔

from运输记录 a, 运输记录 b

where a.货车编号 = b.货车编号

and a.货运单编号 <>b.货运单编号

and a.运输日期 <b.运输日期

and not exists (select 1 from 运输记录 c where a.货车编号 = c.货车编号 and c.运输日期 between a.运输日期 and b.运输日期)

group by a.货车编号) t

order by 最长间隔) t1,

货车, 司机

where t1.货车编号 = 货车.货车编号

and 货车.司机 = 司机.司机

order by 最长间隔 desc

第二题:

select top 1 tmonth as 最忙月份, cnt as 运输次数, 运入总量, 运出总量

FROM

(select month(运输日期) as tmonth,

count(1) as cnt,

sum(case 交易类型 when '运入' then 运输量 else 0 end ) as 运入总量,

sum(case 交易类型 when '运出' then 运输量 else 0 end ) as 运出总量

from 运输记录

where year(运输日期) = 2009

group by tmonth) t

order by t.cnt desc

1.DISTINCT、top

2.convert

3.查询、更新、管理

4.主键、外键

5.ROLLBACK TRAN、COMMIT TRAN

6.sp_renamedb

8.identity

9.插入数据的列数必须和表中列数相等

10.空

12.truncate

14.原子性、一致性、隔离性、永久性

16.count、avg、len、substring

17.cast

18.windows

19.物理数据表

20.<>、!=


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/sjk/10868033.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-11
下一篇2023-05-11

发表评论

登录后才能评论

评论列表(0条)

    保存