Untitled

mail@pastecode.io avatar
unknown
plain_text
21 days ago
1.9 kB
2
Indexable
Never
-- 1
-- SELECT c.customer_name, a.account_number, a.balance
-- FROM customer c
-- JOIN depositor d ON c.customer_name = d.customer_name
-- JOIN account a ON d.account_number = a.account_number
-- WHERE a.branch_name = 'Perryridge';

-- 2
-- SELECT customer_name FROM customer WHERE SUBSTR(customer_name, 2, 1) IN ('a', 'l');

-- 3
-- SELECT DISTINCT c.customer_name
-- FROM customer c
-- JOIN borrower b ON c.customer_name = b.customer_name
-- JOIN loan l ON b.loan_number = l.loan_number
-- WHERE l.branch_name = 'Perryridge'
-- ORDER BY c.customer_name;

-- 4
-- SELECT DISTINCT c.customer_name
-- FROM customer c
-- JOIN depositor d ON c.customer_name = d.customer_name
-- JOIN borrower b ON c.customer_name = b.customer_name;


-- 5
-- SELECT d.customer_name
-- FROM depositor d
-- GROUP BY d.customer_name
-- HAVING COUNT(d.account_number) = 1;

-- 6
-- SELECT MAX(balance) AS third_highest_balance
-- FROM (
--     SELECT balance, DENSE_RANK() OVER (ORDER BY balance DESC) AS rank
--     FROM account
-- ) 
-- WHERE rank = 3;

-- 7
-- SELECT a.account_number, a.balance, a.branch_name
-- FROM account a
-- JOIN (
--     SELECT branch_name, AVG(balance) AS avg_balance
--     FROM account
--     GROUP BY branch_name
-- ) b ON a.branch_name = b.branch_name
-- WHERE a.balance > b.avg_balance;

-- 8
SELECT DISTINCT c.customer_name
FROM customer c
JOIN branch b ON c.customer_city = b.branch_city;

-- 9
-- SELECT DISTINCT c.customer_name
-- FROM customer c
-- JOIN depositor d ON c.customer_name = d.customer_name;

-- 10 
-- DECLARE
--   num1 NUMBER := 56; 
--   num2 NUMBER := 98; 
--   gcd NUMBER;

--   FUNCTION find_gcd(a NUMBER, b NUMBER) RETURN NUMBER IS
--   BEGIN
--     IF b = 0 THEN
--       RETURN a;
--     ELSE
--       RETURN find_gcd(b, MOD(a, b));
--     END IF;
--   END;

-- BEGIN
--   gcd := find_gcd(num1, num2);
--   DBMS_OUTPUT.PUT_LINE('The GCD of ' || num1 || ' and ' || num2 || ' is ' || gcd);
-- END;
Leave a Comment