Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 0 database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use master
go
drop database if exists ArmyDB
go
create database ArmyDB
go

20 changes: 20 additions & 0 deletions 1 table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use ArmyDB
go
drop table if exists dbo.Soldier
go
create table dbo.Soldier(
SoldierID int not null identity primary key,
FirstName varchar(25) not null constraint ck_Soldier_first_name_cannot_be_blank check(FirstName <> ''),
LastName varchar(25) not null constraint ck_Soldier_last_name_cannot_be_blank check(LastName <> ''),
SSN char(10) not null constraint ck_Soldier_SSN_cannot_exceed_10_digits_and_cannot_have_letters check(SSN like ('[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9]')),
DOB date not null,
PlaceOfResidence varchar(40) not null constraint ck_Soldier_place_of_residence_cannot_be_blank check(PlaceOfResidence <> ''),
DateEnlisted date not null
constraint ck_Soldier_date_enlisted_cannot_be_a_future_date check(DateEnlisted <= getdate()),
ServiceUnit varchar(15) not null
constraint ck_Soldier_service_unit_must_be_air_force_navy_or_ground_force check(ServiceUnit in('Air Force', 'Ground Force', 'Navy')),
Rank varchar(90) not null constraint ck_Soldier_rank_cannot_be_blank check(Rank <> ''),
IQLevel int not null constraint ck_Soldier_IQ_level_must_be_greater_than_0 check(IQLevel > 0),
constraint ck_Soldier_must_be_at_least_17_when_enlisted check(datediff(year, DOB, DateEnlisted) >= 17)
)
go
12 changes: 12 additions & 0 deletions 2 data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use ArmyDB
go

delete Soldier
insert Soldier(FirstName, LastName, SSN, DOB, PlaceOfResidence, DateEnlisted, ServiceUnit, Rank, IQLevel)
select 'Ron', 'Aviad', '54876373-2', '01/01/2000', 'Caesarea', '01/03/2021', 'Air Force', 'sergeant', 95
union select 'Shachar', 'Dotan', '85274136-9', '08/16/2001', 'Jerusalem', '10/01/2020', 'Navy', 'lieutenant colonel', 111
union select 'Osher', 'Sharon', '95135778-2', '05/04/1996', 'Tel-Aviv', '04/01/2017', 'Ground Force', 'sergeant', 79
union select 'Yoni', 'Tamari', '24863570-5', '11/23/1999', 'Jerusalem', '12/01/2018', 'Air Force', 'lieutenant general', 139
union select 'Shai', 'Ben Zeev', '93185378-1', '09/13/2001', 'Netanya', '01/01/2020', 'Air Force', 'sergeant', 120
union select 'Dory', 'Lavie', '16834952-7', '10/28/2004', 'Haifa', '12/01/2021', 'Navy', 'brigadier general', 118

25 changes: 25 additions & 0 deletions 3 reports.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

--1) Show a list of all soldiers with all details sorted by IQ level from high to low.
select *
from Soldier s
order by s.IQLevel desc

--2) I need a list of all soldiers sorted by age at enlistment from high to low. Do not include columns that are not relevant to this list.
select AgeAtEnlistment = datediff(year, s.DOB, s.DateEnlisted), s.LastName
from Soldier s
order by AgeAtEnlistment desc

/* 3) Following an upward trend in recruitment since the outbreak of Covid, I need data on recruitment between the years 2017-2019 compared to the years 2020-2022.
The format should be as follows :Year Range (2017-2019/2020-2022), First Name Last Name - SSN (date of enlistment), service unit.
(This should be done by using a union select and adding a literal column for year range.) */
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The report specifies how to do it. But it's ok

select YearRange =
case
when year(s.DateEnlisted) between 2017 and 2019 then '2017-2019'
when year(s.DateEnlisted) between 2020 and 2022 then '2020-2022'
end
, SoldierInfo = concat(s.FirstName, ' ', s.LastName, ' - ', s.SSN, ' (', s.DateEnlisted, '), ',s.ServiceUnit)
from Soldier s
--4) I need to know what the average IQ level is for soldiers per service unit.
select AvgIQ = avg(s.IQLevel), s.ServiceUnit
from Soldier s
group by s.ServiceUnit
5 changes: 0 additions & 5 deletions README.md

This file was deleted.

51 changes: 0 additions & 51 deletions airline.sql

This file was deleted.

File renamed without changes.
77 changes: 0 additions & 77 deletions cleaning company.sql

This file was deleted.

63 changes: 0 additions & 63 deletions confectionery.sql

This file was deleted.

Loading