Skip to content

Instantly share code, notes, and snippets.

@debuggerpk
Last active December 30, 2016 08:18
Show Gist options
  • Select an option

  • Save debuggerpk/565eb6e9f09c8a375eaa2b3186fdce5b to your computer and use it in GitHub Desktop.

Select an option

Save debuggerpk/565eb6e9f09c8a375eaa2b3186fdce5b to your computer and use it in GitHub Desktop.
creating view
CREATE VIEW "lineitems_vista" AS
SELECT
id,
created_at,
updated_at,
shift_id,
itms.name as name,
quantity,
transaction_id,
itms.price as unit_price,
itms.price*quantity as item_total,
itms.category_id,
category,
family
FROM line_items
LEFT JOIN (
SELECT name, price, category_id, id as iid FROM items
) as itms ON line_items.item_id = itms.iid
LEFT JOIN (
SELECT created_at, updated_at, shift_id, id as tid FROM transactions
) as trnsctns ON line_items.transaction_id = trnsctns.tid
LEFT JOIN (
SELECT family, name as category, id as cid FROM categories
) as ctgrs ON itms.category_id = ctgrs.cid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment