-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
157 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
CREATE VIEW cust_agg AS | ||
SELECT ARRAY_AGG((c_id + c_w_id + c_d_id) ORDER BY c_first) AS cust_array | ||
SELECT c_w_id, c_d_id, ARRAY_AGG(c_id ORDER BY c_first) AS cust_array | ||
FROM (SELECT c.c_id, c.c_w_id, c.c_d_id, c.c_first | ||
FROM customer AS c, | ||
transaction_parameters AS t | ||
WHERE c.c_last = t.c_last | ||
AND c.c_d_id = t.c_d_id | ||
AND c.c_w_id = t.c_w_id | ||
ORDER BY c_first); | ||
AND c.c_w_id = t.c_w_id) | ||
GROUP BY c_w_id, c_d_id; | ||
|
||
CREATE VIEW cust_byname AS | ||
SELECT c.c_first, c.c_middle, c.c_id, | ||
SELECT c.c_first, c.c_middle, c.c_last, c.c_id, c.c_w_id, c.c_d_id, | ||
c.c_street_1, c.c_street_2, c.c_city, c.c_state, c.c_zip, | ||
c.c_phone, c.c_credit, c.c_credit_lim, | ||
c.c_discount, c.c_balance, c.c_since | ||
FROM customer as c, | ||
cust_agg as a, | ||
transaction_parameters as t | ||
WHERE (c.c_id + c.c_w_id + c.c_d_id) = a.cust_array[(ARRAY_LENGTH(a.cust_array) / 2) + 1]; | ||
WHERE c.c_w_id = a.c_w_id | ||
AND c.c_d_id = a.c_d_id | ||
AND c.c_id = a.cust_array[(ARRAY_LENGTH(a.cust_array) / 2) + 1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters