Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Omid Lavakhamseh
lab2
Commits
a17c4971
Commit
a17c4971
authored
2 years ago
by
Omid Lavakhamseh
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
21ec03ff
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assignment2_codes.sql
+68
-0
68 additions, 0 deletions
Assignment2_codes.sql
with
68 additions
and
0 deletions
Assignment2_codes.sql
0 → 100644
+
68
−
0
View file @
a17c4971
use
omila405
;
#
Q1
:
select
*
from
jbemployee
;
#
Q2
:
select
name
from
jbdept
order
by
name
;
#
Q3
:
SELECT
*
FROM
jbitem
where
qoh
=
0
;
#
Q4
:
select
*
from
jbemployee
where
salary
between
9000
and
10000
;
#
Q5
:
select
name
,
startyear
-
birthyear
AS
'Age'
from
jbemployee
;
#
Q6
:
select
*
from
jbemployee
where
name
regexp
'son,'
;
#
Q7
:
select
*
from
jbitem
where
supplier
=
(
select
id
from
jbsupplier
where
name
=
'Fisher-Price'
);
#
Q8
:
select
jbitem
.
*
,
jbsupplier
.
name
as
supplierName
from
jbitem
join
jbsupplier
on
jbitem
.
supplier
=
jbsupplier
.
id
where
jbsupplier
.
name
=
"Fisher-Price"
;
#
Q9
:
select
city
.
id
,
city
.
name
,
sup
.
city
from
jbsupplier
sup
left
join
jbcity
city
on
city
.
id
=
sup
.
city
;
#
Q10
:
select
name
,
color
from
jbparts
where
weight
>
(
select
weight
from
jbparts
where
name
=
'card reader'
);
#
Q11
:
select
p1
.
name
,
p1
.
color
,
p1
.
weight
from
jbparts
p1
join
jbparts
p2
on
p2
.
name
=
'card reader'
where
p1
.
weight
>
p2
.
weight
;
#
Q12
:
select
AVG
(
weight
)
from
jbparts
where
color
=
'black'
;
#
Q13
:
select
p
.
name
as
part_name
,(
sup
.
quan
*
p
.
weight
)
as
total_weight
,
c
.
state
from
jbsupply
sup
left
join
jbparts
p
on
sup
.
part
=
p
.
id
join
jbsupplier
on
jbsupplier
.
id
=
sup
.
supplier
join
jbcity
c
on
c
.
id
=
jbsupplier
.
city
where
c
.
state
=
'Mass'
;
#
Q14
:
create
table
item_copy
as
select
*
from
jbitem
where
price
<
(
select
AVG
(
price
)
from
jbitem
)
;
#
Q15
:
create
view
item_copy_view
as
select
*
from
jbitem
where
price
<
(
select
AVG
(
price
)
from
jbitem
)
;
#
Q16
:
view
is
an
virtial
table
and
saves
in
views
.
It
doesn
't have rows(tuples) and columns(attributes) like tables.
#View depends on tables so it is dynamic, table is independant and static.
#Refrence:https://pediaa.com
#Q17:
create view view2 as
select jbdebit.id,(jbsale.item*jbsale.quantity) as total_cost from jbdebit left join jbsale on jbdebit.id=jbsale.debit;
#Q18:
select debit , (jbsale.quantity*jbitem.price) as total from jbsale join jbitem on jbsale.item=jbitem.id;
#Q19:
SET SQL_SAFE_UPDATES = 0;
SET FOREIGN_KEY_CHECKS=0; -- to disable them
DELETE jbsupplier
from jbsupplier
INNER JOIN jbcity on jbsupplier.city = jbcity.id
where jbcity.name="Los Angeles";
SET FOREIGN_KEY_CHECKS=1; -- to re-enable them
SET SQL_SAFE_UPDATES = 1;
#Q20:
create view jbsale_supply2(supplier,item,quantity) AS
select jbsupplier.name,jbitem.name,jbitem.qoh
from jbsupplier,jbitem
where jbsupplier.id=jbitem.supplier;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment