Created
May 1, 2015 23:26
-
-
Save renzok/2e776ee0dd98da7225dd to your computer and use it in GitHub Desktop.
sql array based search
This file contains hidden or 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
with pizzas AS( | |
select p.pizzaid, p.name, p.calzone, | |
i.imageid, i.url, i.copyrightshort, i.copyrightlong, | |
amount, diameter, curcurrency, array_agg(trim(t.name)) as toppings, string_agg(t.name, ',') | |
from pizza p | |
LEFT JOIN image i On (p.imageid = i.imageid) | |
LEFT JOIN pizzasizeprice psp on (p.pizzaid = psp.pizzaid) | |
LEFT JOIN price on (psp.priceid = price.priceid) | |
LEFT JOIN size ON (psp.sizeid = size.sizeid) | |
JOIN pizzatopping pt ON(p.pizzaid = pt.pizzaid) | |
LEFT JOIN topping t on(pt.toppingid = t.toppingid) | |
WHERE amount Between 5 and 10 | |
AND diameter = 32 | |
group by p.pizzaid, p.name, p.calzone, | |
i.imageid, i.url, i.copyrightshort, i.copyrightlong, amount,diameter,curcurrency | |
) | |
select * | |
from pizzas p | |
where toppings @> Array['Tomaten', 'Oliven'] | |
order by pizzaid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WHERE amount Between minPrize and maxPrize
AND diameter = size
group by p.pizzaid, p.name, p.calzone,
i.imageid, i.url, i.copyrightshort, i.copyrightlong, amount,diameter,curcurrency
)
select *
from pizzas p
where toppings @> Array[ String[0], String[1]] -- in etwa so
order by pizzaid