0% found this document useful (0 votes)
13 views

SQL

Uploaded by

agrodonia
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

SQL

Uploaded by

agrodonia
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 24

books

id title language author_id editor_id


1 learning coding english 11 21
2 ilove excel german 15 22
3 python spanish 14 24
4 SQL Basics english 11 24
5 my first book german 12 25
6 C++ spanish 14 22
7 Visual Basic spanish 11 23
8 Data Analysis german 10 28

SQL Query
select title,author_id from a where language='german'
16 15
14
author_id
12
12
10
8
Query Result: 6
#NAME? #NAME? title author_id
4
#NAME? #NAME? ilove excel 15
2
#NAME? #NAME? my first book 12
#NAME? #NAME? 0
Data Analysis 10

select count(title) as qty , language from a group by language


#NAME? #NAME?
#NAME? #NAME?
#NAME? #NAME?
#NAME? #NAME?
authors editors
author_id first_name last_name id first_name last_name
11 ahmed mohamed 1 mahmoud samar
12 said ibrahim 22 samir mayar
13 mohamed sayed 23 racha moaz
14 khamis shafiq 24 riham mohi
15 wael shrif 25 latifa walid
26 sawsan sayed
27 risq shrif

SQL Query ,b.last_name as editor_last from


SELECT
16 15
author_id a.title,
14
12
a.author_id,
12 b.last_name AS editor_last_name
10
10
FROM
8
a
INNER JOIN
Query Result:
6
#NAME? #NAME? #NAME?
4
#NAME? #NAME? #NAME?
2
0
last_name as editor_last from a inner join b on a.editor_id=b.author_id
Students Table:
student_id first_name last_name date_of_birth grade_level
1 John Smith 3/15/2005 10
2 Sarah Johnson 6/22/2006 9
3 Michael Davis 9/10/2007 9
4 Emily Wilson 1/30/2006 10

Teachers Table:
teacher_id first_name last_name subject email
1 Mr. Anderson Mathematics [email protected]
2 Ms. Brown Science [email protected]
3 Mrs. Clark English [email protected]
4 Dr. Evans History [email protected]

Classes Table:
class_id class_name teacher_id room_number schedule
101 Math 101 1 A-101 Monday, 9:00 AM

102 Science 102 2 B-205 Tuesday, 10:30 AM

103 English 101 3 C-301 Wednesday, 8:15 AM


104 History 102 4 D-102 Thursday, 11:45 AM

Enrollments Table:
enrollment_id student_id class_id enrollment_date
1 1 101 8/15/2023
2 2 102 8/15/2023
3 3 101 8/15/2023
4 4 103 8/15/2023

Grades Table:
grade_id student_id class_id assignment score
1 1 101 Midterm 85.5

2 1 101 Homework 1 92

3 2 102 Quiz 1 78
4 2 102 Quiz 2 84.5

5 3 101 Homework 1 88.5

6 3 101 Homework 2 95

7 4 103 Essay 1 89
8 4 103 Essay 2 91.5
Attendance Table:
attendance_id student_id class_id date status
1 1 101 9/3/2023 Present
2 2 102 9/3/2023 Present
3 3 101 9/3/2023 Present
4 4 103 9/3/2023 Present

ChatGPT

Students
Table:

Teachers
Table:

Classes
Table:
Enrollments
Table:

Attendance
Table:
Many-to-
One
Relationshi
p with
Classes
Table:
Each
attendance
record is
associated
with one
class, so
there is a
many-to-
one
relationshi
p between
attendance.cla
ss_id and
classes.class_
id.
s represent
how the
tables are
connected
and how
data flows
between
them in the
database. In
an ERD
diagram,
you would
typically
visualize
these
relationship
s using lines
connecting
the tables,
along with
cardinality
indicators to
show the
type of
relationship
(one-to-
many,

draw Entity-
Relationship
Diagram
(ERD)
between
tables
ChatGPT
I'm sorry for
any
confusion,
but I can't
create
visual
diagrams or
images
directly in
this text-
based
interface.
However, I
can provide
a textual
representati
on of the
Entity-
Relationship
Diagram
(ERD)
between the
tables in
your
secondary
school
database:
cssCopy code
Students [student_id(PK), first_name, last_name, date_of_birth, grade_level, address, parent_email]
|
|___ Enrollments [enrollment_id(PK), student_id(FK), class_id(FK), enrollment_date]

Teachers [teacher_id(PK), first_name, last_name, subject, email]


|
|___ Classes [class_id(PK), class_name, teacher_id(FK), room_number, schedule]

Grades [grade_id(PK), student_id(FK), class_id(FK), assignment, score, date]

Attendance [attendance_id(PK), student_id(FK), class_id(FK), date, status]


In this
textual
representati
on:

Square
brackets []
represent
tables.
Inside the
brackets,
you see
the table
name
followed by
the list of
columns
with their
respective
primary
key (PK)
and foreign
key (FK)
indications.
this
representati
on as a
guide to
create an
actual ERD
using
diagrammin
g tools like
Lucidchart,
draw.io, or
database
design
software.
These tools
allow you to
visually
represent
the tables
and their
relationship
s, making it
easier to
understand
the
database

draw
connection
between
table as is in
power query

ChatGPT
In Power
Query, you
can visually
represent
the
connections
between
tables using
a graphical
interface.
Here's how
you can
create
connections
between
tables in
Power
Query:
Open
Power
Query
Editor:
First, load
your data
into Power
Query by
going to
the "Data"
tab in
Excel and
selecting
"Get Data"
or "Get &
Transform
Data"
(depending
on your
Excel
version).
Load
Tables:
Load the
tables you
want to
connect
into the
Power
Query
Editor. You
can do this
by
selecting
the tables
from your
data
source
(e.g., Excel
workbook,
database,
CSV file).
Join Tables:
To
establish
connection
s between
tables, you
can use
the "Join"
operation.
Follow
these steps
for each
connection
you want
to create:

Select one
of the
tables by
clicking
on it.
Go to the
"Home"
tab in
Power
Query
Editor.

Click on
the "Join
Queries"
dropdown
.
Choose
the type
of join you
want to
perform
(e.g.,
Inner Join,
Left Outer
Join).

Select the
second
table to
join with.
Define the
join
conditions
by
specifying
the
columns
from each
table that
should
match.
Load the
Result:
After
defining
the
connection
s and
performing
any
necessary
data
transforma
tions, you
can load
the result
into Excel
or your
desired
destination
.
The actual
process
may vary
slightly
depending
on your
specific use
case and
data source.
Power
Query
provides a
user-friendly
way to
create and
manage
connections
between
tables,
allowing you
to combine
and
transform
data as
needed.
Unfortunatel
y, I cannot
provide a
visual
representati
on of Power
Query
operations
in this text-
based
interface,
but you
should be
able to
follow the
steps
outlined
above to
create
connections
between
tables
within
Power
Query.
address parent_email
123 Main St, Anytown, USA [email protected]
456 Elm St, Othertown, USA [email protected]
789 Oak St, Different City [email protected]
101 Pine St, Nearby City [email protected]

date
9/5/2023

8/25/2023

8/30/2023
9/5/2023

8/25/2023

9/5/2023

9/1/2023
9/10/2023
ent_email]

You might also like