9 Eylül 2021 Perşembe

CREATE VIEW

Örnek - WHERE Koşulu
Şöyle yaparız
-- Create a view that pre-aggregates the spending data for each user over the last year
CREATE VIEW user_spending_last_year AS
  SELECT user_id, SUM(amount) AS total_spending
  FROM transactions
  WHERE transaction_date >= '2022-01-01'
  GROUP BY user_id;
Örnek - İki Tabloyu Birleştirmek
Elimizde iki tablo olsun
CREATE TABLE staff(
   id INT,
   age INT,
   address TEXT
);
 
 
CREATE TABLE salary(
   sal_id INT,
   salary INT,
   division TEXT
);
Şöyle yaparız
CREATE VIEW STAFF_SALARY_COMBINED AS (
	SELECT * 
	FROM staff,salary 
	WHERE id=sal_id
);

Hiç yorum yok:

Yorum Gönder