wonderful-sql 作业

这篇具有很好参考价值的文章主要介绍了wonderful-sql 作业。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Sql 作业

作业1:

wonderful-sql 作业,sql,数据库,java

答:

create table Employee
(Id integer not null,
Name varchar(32) ,
Salary integer,
departmentId integer,
primary key (Id)
);

create table Department(
Id integer primary key,
Name varchar(30) not null
);

insert into employee values (1,"Joe",70000,1);
insert into employee values (2,"Henry",80000,2);
insert into employee values (3,"Sam",60000,2);
insert into employee values (4,"Max",90000,1);
insert into department values(1,"IT");
insert into department values(2,"Sales");

SELECT departmentId,  (
    SELECT Name FROM employee
    WHERE departmentId = e.departmentId AND salary = MAX(e.salary)
) AS Employee,MAX(salary) AS max_salary
FROM employee e
GROUP BY departmentId

wonderful-sql 作业,sql,数据库,java

wonderful-sql 作业,sql,数据库,java

答:

create table seat(
id int primary key,
Name varchar(30) not null
);
insert into seat values(1,"Abbot");
insert into seat values(2,"Doris");
insert into seat values(3,"Emerson");
insert into seat values(4,"Green");
insert into seat values(5,"Jeames");
select * from seat;

SELECT(
    CASE 
        WHEN MOD(id,2)=1 AND id=(SELECT COUNT(id) FROM seat) THEN id
        WHEN MOD(id,2)=0 THEN id-1
        ELSE id+1
    END
) AS id
    ,name
FROM seat
ORDER BY id;


wonderful-sql 作业,sql,数据库,java

解决相关方法:

wonderful-sql 作业,sql,数据库,java

答:

create table score(
class int primary key,
score_avg int 
);
insert into score values(1,93);
insert into score values(2,93);
insert into score values(3,93);
insert into score values(4,91);
select class,score_avg,
rank() over (order by score_avg desc) as rank1,
dense_rank() over (order by score_avg desc) as rank2,
row_number() over(order by score_avg desc) as rank3
from score;

wonderful-sql 作业,sql,数据库,java

答:

create table number(
id int primary key,
Num int
);
insert into number values(1,1); 
insert into number values(2,1);
insert into number values(3,1);
insert into number values(4,2);
insert into number values(5,1);
insert into number values(6,2);
insert into number values(7,2);
select * from number;
select distinct num as ConsecutiveNums
from (select num,if(@prev_num = num,@count:=@count+1,@count:=1)
 as consecutive_count, @prev_num:=num
 from number
 cross join(select @count:=0,@prev_num:=NULL) as vars
 order by id
)as t
where consecutive_count>=3
 

wonderful-sql 作业,sql,数据库,java
wonderful-sql 作业,sql,数据库,java

答:

create table tree(
id int primary key,
p_id int
);
insert into tree values(1,null);
insert into tree values(2,1);
insert into tree values(3,1);
insert into tree values(4,2);
insert into tree values(5,2);
select * from tree;
select id , case
	when p_id is null then "Root"
    when id in (select p_id from tree) then "Inner"
    else "Leaf"
    end as Type
    from tree;

wonderful-sql 作业,sql,数据库,java

答:

create table Employee2(
Id int primary key,
name varchar(50),
Department varchar(50),
ManagerId int
);
insert into employee2 values(101,"John","A",null);
insert into employee2 values(102,"Dan","A",101);
insert into employee2 values(103,"James","A",101);
insert into employee2 values(104,"Amy","A",101);
insert into employee2 values(105,"Anne","A",101);
insert into employee2 values(106,"Ron","B",101);
select * from employee2;
select name
from (select ManagerId , count(ManagerId) as M_count
from employee2
group by ManagerId
) as ManagerCount , employee2
where ManagerCount.M_count = 5 and ManagerCount.ManagerId = employee2.Id

wonderful-sql 作业,sql,数据库,java

wonderful-sql 作业,sql,数据库,java

答:

drop table if exists survey_log;
create table survey_log(
uid int ,
action varchar(20) check(action = "show" or action="answer" or action = "skip"),
question_id int,
answer_id int,
q_num int,
timestamp timestamp
);
insert into survey_log values(5,"show",285,null,1,123);
insert into survey_log values(5,"answer",285,124124,1,124);
insert into survey_log values(5,"show",369,null,2,125);
insert into survey_log values(5,"skip",369,null,2,126);
select * from survey_log;
select * from survey_log 
where action = "show" or action = "answer";
select question_id, count(*) as show1 from  survey_log
where action = "show"
group by question_id;

select count_answer.question_id,max(answer/show1)
from
(select question_id, count(*) as show1 from  survey_log
where action = "show"
group by question_id) as count_show,
(select question_id, count(*) as answer from  survey_log
where action = "answer"
group by question_id) as count_answer
where count_answer.question_id  = count_show.question_id
group by count_answer.question_id

wonderful-sql 作业,sql,数据库,java
答:文章来源地址https://www.toymoban.com/news/detail-628326.html

select * from employee;
select * from department;
insert into employee value(5,"Janet",69000,1);
insert into employee value(6,"Randy",85000,1);
select department.Name as department,rank_employee.name as Employee,Salary
from (select name,salary,departmentId,
row_number() over (partition by departmentId order by salary desc) as rank1
from employee) 
as rank_employee,department
 where rank1 <=3 and department.id = rank_employee.departmentId

到了这里,关于wonderful-sql 作业的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 利用java.sql包--访问和处理数据库数据

    The java.sql package in Java provides the API for interacting with relational databases using JDBC (Java Database Connectivity). JDBC is a standard Java API that allows Java programs to connect to and interact with various database management systems (DBMS) using SQL (Structured Query Language). The java.sql package contains several important interfaces and

    2024年02月10日
    浏览(38)
  • 通过Java连接Sql Server数据库

    JDBC是Java DateBase Connectivity的简写,翻译过来就是java连接数据库,或者更通俗地说就是java语言操作数据库。JDBC的本质其实是官方定义的一套操作所有关系型数据库的规则,也就是接口。 微软官方jdbc下载地址:https://www.microsoft.com/zh-cn/download/details.aspx?id=11774 下载之后解压到相

    2024年01月17日
    浏览(52)
  • Java连接SQL Server数据库的详细操作流程

    1.1 JDK版本查看 win + r输入cmd,命令窗口输入java --version 1.2 SQL Server官网下载驱动 SQL Server驱动下载直达地址 下载完成后解压到自己熟悉的目录,不出意外的话你会看到以下文件 1.3 加载驱动类 1.4 eclipse导入驱动jar包 目录结构 右键当前工程文件,选择 build path ,然后选择 Add Exter

    2024年02月03日
    浏览(65)
  • 学生信息管理系统 Java+SQL Server 数据库原理课程

    该项目实现了图形化界面的数据库的登录,以及对数据库中表的增删查改。 正好老师布置了相关作业,通过Java 连接 SQL Server 数据库,就写一个学生管理系统。 jdk8 数据库连接通过sqljdbc6.0 图形化界面用swing 目录 1、Java 连接SQL Server数据库 2、准备数据库 3、登录界面 要求:

    2024年02月09日
    浏览(65)
  • JAVA编码规范:安全规约、mysql数据库_java后端的sql编码规范

    7、【强制】如果存储的字符串长度几乎相等,使用 char定长字符串类型 8、【强制】varchar是可变长字符串,不预先分配存储空间,长度不要超过 5000,如果存储长度大于此值,定义字段类型为 text,独立出来一张 表,用主键来对应,避免影响其它字段索引效率。 9、【强制】表

    2024年04月10日
    浏览(49)
  • Java从入门到精通24==》数据库、SQL基本语句、DDL语句

    2023.8.27 数据库是一个电子化储存数据的系统,它能够以结构化形式组织、存储和管理数据,使得数据的访问、操作和管理变得更为高效、可靠和安全 数据库通常包括数据、数据结构、查询语言、数据存储和检索引擎等多个组成部分,可分为关系型数据库、非关系型数据库等

    2024年02月11日
    浏览(45)
  • Java一般用于postgis空间数据库通用的增删查改sql命令

    目录 1 增加 2 删除 3 查询 4 更新 \\\"public\\\".\\\"JGSQGW_Geo\\\"为某模式下得表  一般postgrel有这样的设计模式

    2024年02月13日
    浏览(45)
  • 实战Java springboot 采用Flink CDC操作SQL Server数据库获取增量变更数据

    目录 前言: 1、springboot引入依赖: 2、yml配置文件 3、创建SQL server CDC变更数据监听器 4、反序列化数据,转为变更JSON对象 5、CDC 数据实体类 6、自定义ApplicationContextUtil 7、自定义sink 交由spring管理,处理变更数据         我的场景是从SQL Server数据库获取指定表的增量数据,查

    2024年02月10日
    浏览(87)
  • Microsoft SQL Server 2019 下载、安装及Java JDBC配置连接数据库(多图详解 超详细)

    一、下载 下载链接Microsoft SQL Server 二、安装 1.找到刚刚下载的文件,双击打开后,选择基本并接受 2.选择接受 3.选择安装位置,并点击安装,然后等待下载安装完成 4.正在安装 -5.遇到了一个问题,重启一下(未遇到该问题的可忽略此步) 6.安装成功,点击安装SSMS 7.点击下载

    2024年02月04日
    浏览(105)
  • 数据库作业合集

    有一些图没了 自己搜一搜 以下是作业内容 3、习题10 系(系编号,系名,学校名) 班级(班级编号,班级名,系编号) 教研室(教研室编号,教研室名,系编号) 学生(学号,姓名,学历,班级编号,导师职工号) 教员(职工号,姓名,职称,教研室编号) 课程(课程号

    2024年02月02日
    浏览(82)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包