Untitled
Untitled
Untitled
URL: https://forms.gle/42kCAXuYNud96huD9
QR CODE:
JDBC
Aggregate Functions
COUNT FUNCTION
COUNT function is used to Count the number of rows in a
database table. It can work on both numeric and non-numeric
data types.
SUM Function
Sum function is used to calculate the sum of all selected
columns. It works on numeric fields only.
AVG function
The AVG function is used to calculate the average value of
the numeric type. AVG function returns the average of all
non-Null values.
MIN Function
MIN function is used to find the minimum value of a certain column. This
MAX Function
MAX function is used to find the maximum value of a certain column. This
Item1 Com1 2 10 20
Item2 Com2 3 25 75
Item3 Com1 2 30 60
Item4 Com3 5 10 50
Item5 Com2 2 20 40
QUERY
A Primary Key is the minimal set of attributes of a table that has the task to
uniquely identify the rows, or we can say the tuples of the given particular
table.
Syntax
The FOREIGN KEY constraint is used to prevent actions that would destroy links
between tables.
A FOREIGN KEY is a field (or collection of fields) in one table, that refers
to the PRIMARY KEY in another table.
The table with the foreign key is called the child table, and the table with
the primary key is called the referenced or parent table.
PERSON TABLE
1 Hansen Ola 30
2 Svendson Tove 23
3 Pettersen Kari 20
ORDER TABLE
1 77895 3
2 44678 3
3 22456 2
4 24562 1
Creating a Primary Key
MYSQL:
PersonID int,
);
JOINS
SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on
a related column between them.
Different Types of SQL JOINs
(INNER) JOIN: Returns records that have matching values in both tables
LEFT (OUTER) JOIN: Returns all records from the left table, and the
matched records from the right table
RIGHT (OUTER) JOIN: Returns all records from the right table, and the
matched records from the left table
FULL (OUTER) JOIN: Returns all records when there is a match in either
left or right table
TYPES OF JOINS
INNER JOIN
The INNER JOIN keyword selects records that have matching values
in both tables.
SELECT column_name(s)
FROM table1
ON table1.column_name = table2.column_name;
SQL LEFT JOIN
The LEFT JOIN keyword returns all records from the left table
(table1), and the matching records from the right table (table2).
match.
SELECT column_name(s)
FROM table1
ON table1.column_name = table2.column_name;
INNER JOIN
The INNER JOIN keyword selects records that have matching values
in both tables.
SELECT column_name(s)
FROM table1
ON table1.column_name = table2.column_name;
EXAMPLE-ORDER AND
CUSTOMER TABLE
10308 2 7 1996-09-18 3
10309 37 3 1996-09-19 1
10310 77 8 1996-09-20 2
FROM Orders
FROM Customers
ORDER BY Customers.CustomerName;
EXCERISE
4) Write a statement that will select the City column from the
Customers table.
5) Select all records where the City column has the value
You can only see the w numbers in the window. Each time the
sliding window moves rightwards by one position.
Problem Statement
Return an array C, where C[i] is the maximum value from A[i] to A[i+K-1].
If k > length of the array, return 1 element with the max of the array.
Example
Input: A[] = {8, 5, 10, 7, 9, 4, 15, 12, 90, 13}, K = 4
Output: {10, 10, 10, 15, 15, 90, 90}
Explanation
Maximum of first 4 elements is 10, similarly for next 4 elements (i.e from index
1 to 4) is 10, So the sequence generated is 10 10 10 15 15 90 90
Max Sliding Window
Illustration
Explanation
Max Sliding Window
maxslidingwindow1.java
Sample IO
Input
arr = {1, 3, -1, -3, 5, 3, 6, 7} Time Complexity: O(N*k)
k = 3 Space Complexity: O(N – k + 1)
Output
3 3 5 5 6 7
/ethnuscodemithra Ethnus Codemithra /ethnus /code_mithra
https://learn.codemithra.com