0% found this document useful (0 votes)
19 views10 pages

EXP9

Uploaded by

KUNAL PATIL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views10 pages

EXP9

Uploaded by

KUNAL PATIL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Sign.

:Teacher's
enpliably Vale
nos coand beng me
Paa acept can bhuy baoky
pekozonBbeoraceeles
Cancan
ocedres Jored
Fmction-name
ALUgTO_RSTURN RETURN
dECIION EXECUTLOE
BECaIN
bua ASTURN
e
datatype dababype)Lacamabexl
nname FUNLTIGA ToRREPLAE CREATe
eengubabian
ramebens aerp Can Thy xalue. adingle
FUNCTION
PL-4@L Procecue
m
ored Fmcbicna
nd AimLmpleoenya
of bin
Experimen
9
Page
Date
Pane

CREATE LoR AeRLACe


Procecle prrceele name
J8
E(posamefe dabitype-
--Decloabian deicos.
Enecuhon tebios

Ab ekng avalue euheseas a


rocecuse dees nob ebuga value
unein can be Inakecd in a sQL dbabeaent
allowee lheag boed ocecuse Canbe
e

ConLoÈON

<hucceastully lamplemenle! mebn emsd fasedlne

Teacher's Sign.
sql 9
exp6
CREATE TABLE DEP (
department_id INT PRIMARY KEY,
department_name VARCHAR(50),
location_id INT
);
INSERT INTO DEP (department_id, department_name, location_id)
VALUES
(1, 'HR', 1700),
(2, 'Finance', 1800),
(3, 'IT', 1700);

1> USING IN
SELECT *
FROM DEP
WHERE location_id IN (1700, 1800);

2>USING NOT IN
-- Select departments not located in location_id 1700
SELECT *
FROM departments
WHERE location_id NOT IN (1700, 1800);

3>USING ANY
SELECT *
FROM DEP
WHERE department_id IN (
SELECT department_id
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 1
);

4>USING IN
-- Select departments with at least one employee earning more than $60000
SELECT *
FROM department
WHERE department_id IN (
SELECT department_id
FROM employees
WHERE salary > 60000
);

5> USING EXIST


-- Select departments with at least one employee
SELECT *
FROM department d
WHERE EXISTS (
SELECT 1
FROM employees e
WHERE e.department_id = d.department_id
);
6> USING NOT EXIST
-- Select departments with no employees
SELECT *
FROM departments d
WHERE NOT EXISTS (
SELECT 1
FROM employees e
WHERE e.department_id = d.department_id
);

8> USING WITH

-- Select departments along with the total number of employees


WITH department_employee_count AS (
SELECT d.department_id, d.department_name, COUNT(e.employee_id) AS num_employees
FROM departments d
LEFT JOIN employees e ON d.department_id = e.department_id
GROUP BY d.department_id, d.department_name
)
SELECT *
FROM department_employee_count;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy