erDiagram
actor {
int actor_id PK
text first_name
text last_name
datetime last_update
}
address {
int address_id PK
text address
text address2
text district
int city_id FK
text postal_code
text phone
datetime last_update
}
category {
int category_id PK
text name
datetime last_update
}
city {
int city_id PK
text city
int country_id FK
datetime last_update
}
country {
int country_id PK
text country
datetime last_update
}
customer {
int customer_id PK
int store_id FK
text first_name
text last_name
text email
int address_id FK
bool active
datetime create_date
datetime last_update
}
film {
int film_id PK
text title
text description
int release_year
int language_id FK
int original_language_id FK
int rental_duration
decimal rental_rate
int length
decimal replacement_cost
unknown rating
unknown special_features
datetime last_update
}
film_actor {
int actor_id PK,FK
int film_id PK,FK
datetime last_update
}
film_category {
int film_id PK,FK
int category_id PK,FK
datetime last_update
}
film_text {
int film_id PK
text title
text description
}
inventory {
int inventory_id PK
int film_id FK
int store_id FK
datetime last_update
}
language {
int language_id PK
text name
datetime last_update
}
payment {
int payment_id PK
int customer_id FK
int staff_id FK
int rental_id FK
decimal amount
datetime payment_date
datetime last_update
}
rental {
int rental_id PK
datetime rental_date
int inventory_id FK
int customer_id FK
datetime return_date
int staff_id FK
datetime last_update
}
staff {
int staff_id PK
text first_name
text last_name
int address_id FK
bytes picture
text email
int store_id FK
bool active
text username
text password
datetime last_update
}
store {
int store_id PK
int manager_staff_id FK
int address_id FK
datetime last_update
}
actor_info {
int actor_id
text first_name
text last_name
text film_info
}
customer_list {
int id
text name
text address
text zip_code
text phone
text city
text country
text notes
int sid
}
film_list {
int fid
text title
text description
text category
decimal price
int length
unknown rating
text actors
}
nicer_but_slower_film_list {
int fid
text title
text description
text category
decimal price
int length
unknown rating
text actors
}
sales_by_film_category {
text category
decimal total_sales
}
sales_by_store {
text store
text manager
decimal total_sales
}
staff_list {
int id
text name
text address
text zip_code
text phone
text city
text country
int sid
}
city ||--o{ address : "address_city_id_fkey"
country ||--o{ city : "city_country_id_fkey"
address ||--o{ customer : "customer_address_id_fkey"
store ||--o{ customer : "customer_store_id_fkey"
language |o--o{ film : "film_original_language_id_fkey"
language ||--o{ film : "film_language_id_fkey"
actor ||--o{ film_actor : "film_actor_actor_id_fkey"
film ||--o{ film_actor : "film_actor_film_id_fkey"
category ||--o{ film_category : "film_category_category_id_fkey"
film ||--o{ film_category : "film_category_film_id_fkey"
film ||--o{ inventory : "inventory_film_id_fkey"
store ||--o{ inventory : "inventory_store_id_fkey"
customer ||--o{ payment : "payment_customer_id_fkey"
rental |o--o{ payment : "payment_rental_id_fkey"
staff ||--o{ payment : "payment_staff_id_fkey"
customer ||--o{ rental : "rental_customer_id_fkey"
inventory ||--o{ rental : "rental_inventory_id_fkey"
staff ||--o{ rental : "rental_staff_id_fkey"
address ||--o{ staff : "staff_address_id_fkey"
store ||--o{ staff : "staff_store_id_fkey"
address ||--o{ store : "store_address_id_fkey"
staff ||--o{ store : "store_manager_staff_id_fkey"
erDiagram
address {
int address_id PK
text address
text address2
text district
int city_id FK
text postal_code
text phone
datetime last_update
}
city ||--o{ address : "address_city_id_fkey"
address ||--o{ customer : "customer_address_id_fkey"
address ||--o{ staff : "staff_address_id_fkey"
address ||--o{ store : "store_address_id_fkey"
erDiagram
city {
int city_id PK
text city
int country_id FK
datetime last_update
}
city ||--o{ address : "address_city_id_fkey"
country ||--o{ city : "city_country_id_fkey"
erDiagram
customer {
int customer_id PK
int store_id FK
text first_name
text last_name
text email
int address_id FK
bool active
datetime create_date
datetime last_update
}
address ||--o{ customer : "customer_address_id_fkey"
store ||--o{ customer : "customer_store_id_fkey"
customer ||--o{ payment : "payment_customer_id_fkey"
customer ||--o{ rental : "rental_customer_id_fkey"
erDiagram
film {
int film_id PK
text title
text description
int release_year
int language_id FK
int original_language_id FK
int rental_duration
decimal rental_rate
int length
decimal replacement_cost
unknown rating
unknown special_features
datetime last_update
}
language |o--o{ film : "film_original_language_id_fkey"
language ||--o{ film : "film_language_id_fkey"
film ||--o{ film_actor : "film_actor_film_id_fkey"
film ||--o{ film_category : "film_category_film_id_fkey"
film ||--o{ inventory : "inventory_film_id_fkey"
erDiagram
inventory {
int inventory_id PK
int film_id FK
int store_id FK
datetime last_update
}
film ||--o{ inventory : "inventory_film_id_fkey"
store ||--o{ inventory : "inventory_store_id_fkey"
inventory ||--o{ rental : "rental_inventory_id_fkey"
erDiagram
language {
int language_id PK
text name
datetime last_update
}
language |o--o{ film : "film_original_language_id_fkey"
language ||--o{ film : "film_language_id_fkey"
erDiagram
staff {
int staff_id PK
text first_name
text last_name
int address_id FK
bytes picture
text email
int store_id FK
bool active
text username
text password
datetime last_update
}
staff ||--o{ payment : "payment_staff_id_fkey"
staff ||--o{ rental : "rental_staff_id_fkey"
address ||--o{ staff : "staff_address_id_fkey"
store ||--o{ staff : "staff_store_id_fkey"
staff ||--o{ store : "store_manager_staff_id_fkey"
erDiagram
store {
int store_id PK
int manager_staff_id FK
int address_id FK
datetime last_update
}
store ||--o{ customer : "customer_store_id_fkey"
store ||--o{ inventory : "inventory_store_id_fkey"
store ||--o{ staff : "staff_store_id_fkey"
address ||--o{ store : "store_address_id_fkey"
staff ||--o{ store : "store_manager_staff_id_fkey"
erDiagram
actor_info {
int actor_id
text first_name
text last_name
text film_info
}
View definition:
SELECT a.actor_id,
a.first_name,
a.last_name,
string_agg(DISTINCT (c.name::text || ': '::text) || (( SELECT group_concat(f.title::text ORDER BY f.title) AS group_concat
FROM film f
JOIN film_category fc_1 ON f.film_id = fc_1.film_id
JOIN film_actor fa_1 ON f.film_id = fa_1.film_id
WHERE fc_1.category_id = c.category_id AND fa_1.actor_id = a.actor_id
GROUP BY fa_1.actor_id)), '; '::text) AS film_info
FROM actor a
LEFT JOIN film_actor fa ON a.actor_id = fa.actor_id
LEFT JOIN film_category fc ON fa.film_id = fc.film_id
LEFT JOIN category c ON fc.category_id = c.category_id
GROUP BY a.actor_id, a.first_name, a.last_name;
erDiagram
customer_list {
int id
text name
text address
text zip_code
text phone
text city
text country
text notes
int sid
}
View definition:
SELECT cu.customer_id AS id,
(cu.first_name::text || ' '::text) || cu.last_name::text AS name,
a.address,
a.postal_code AS "zip code",
a.phone,
city.city,
country.country,
CASE
WHEN cu.active THEN 'active'::text
ELSE ''::text
END AS notes,
cu.store_id AS sid
FROM customer cu
JOIN address a ON cu.address_id = a.address_id
JOIN city ON a.city_id = city.city_id
JOIN country ON city.country_id = country.country_id;
erDiagram
film_list {
int fid
text title
text description
text category
decimal price
int length
unknown rating
text actors
}
View definition:
SELECT film.film_id AS fid,
film.title,
film.description,
category.name AS category,
film.rental_rate AS price,
film.length,
film.rating,
group_concat((actor.first_name::text || ' '::text) || actor.last_name::text ORDER BY actor.first_name, actor.last_name, actor.actor_id) AS actors
FROM category
LEFT JOIN film_category ON category.category_id = film_category.category_id
LEFT JOIN film ON film_category.film_id = film.film_id
JOIN film_actor ON film.film_id = film_actor.film_id
JOIN actor ON film_actor.actor_id = actor.actor_id
GROUP BY film.film_id, film.title, film.description, category.name, film.rental_rate, film.length, film.rating;
erDiagram
nicer_but_slower_film_list {
int fid
text title
text description
text category
decimal price
int length
unknown rating
text actors
}
View definition:
SELECT film.film_id AS fid,
film.title,
film.description,
category.name AS category,
film.rental_rate AS price,
film.length,
film.rating,
group_concat((((upper("substring"(actor.first_name::text, 1, 1)) || lower("substring"(actor.first_name::text, 2))) || ' '::text) || upper("substring"(actor.last_name::text, 1, 1))) || lower("substring"(actor.last_name::text, 2)) ORDER BY actor.first_name, actor.last_name, actor.actor_id) AS actors
FROM category
LEFT JOIN film_category ON category.category_id = film_category.category_id
LEFT JOIN film ON film_category.film_id = film.film_id
JOIN film_actor ON film.film_id = film_actor.film_id
JOIN actor ON film_actor.actor_id = actor.actor_id
GROUP BY film.film_id, film.title, film.description, category.name, film.rental_rate, film.length, film.rating;
erDiagram
sales_by_film_category {
text category
decimal total_sales
}
View definition:
SELECT c.name AS category,
sum(p.amount) AS total_sales
FROM payment p
JOIN rental r ON p.rental_id = r.rental_id
JOIN inventory i ON r.inventory_id = i.inventory_id
JOIN film f ON i.film_id = f.film_id
JOIN film_category fc ON f.film_id = fc.film_id
JOIN category c ON fc.category_id = c.category_id
GROUP BY c.name
ORDER BY (sum(p.amount)) DESC;
erDiagram
sales_by_store {
text store
text manager
decimal total_sales
}
View definition:
SELECT (c.city::text || ','::text) || cy.country::text AS store,
(m.first_name::text || ' '::text) || m.last_name::text AS manager,
sum(p.amount) AS total_sales
FROM payment p
JOIN rental r ON p.rental_id = r.rental_id
JOIN inventory i ON r.inventory_id = i.inventory_id
JOIN store s ON i.store_id = s.store_id
JOIN address a ON s.address_id = a.address_id
JOIN city c ON a.city_id = c.city_id
JOIN country cy ON c.country_id = cy.country_id
JOIN staff m ON s.manager_staff_id = m.staff_id
GROUP BY cy.country, c.city, s.store_id, m.first_name, m.last_name
ORDER BY cy.country, c.city;
erDiagram
staff_list {
int id
text name
text address
text zip_code
text phone
text city
text country
int sid
}
View definition:
SELECT s.staff_id AS id,
(s.first_name::text || ' '::text) || s.last_name::text AS name,
a.address,
a.postal_code AS "zip code",
a.phone,
city.city,
country.country,
s.store_id AS sid
FROM staff s
JOIN address a ON s.address_id = a.address_id
JOIN city ON a.city_id = city.city_id
JOIN country ON city.country_id = country.country_id;