Condition:
There are two tables with arrays.
Note food.integer and price.food_id specified array.
CREATE TABLE food (
id integer[] NOT NULL,
name character varying(255),
);
INSERT INTO food VALUES ('{1}', 'Apple');
INSERT INTO food VALUES ('{1,1}', 'Orange');
INSERT INTO food VALUES ('{1,2}', 'banana');
and
CREATE TABLE price (
id bigint NOT NULL,
food_id integer[],
value double precision DEFAULT 0
);
INSERT INTO price VALUES (44, '{1}', 500);
INSERT INTO price VALUES (55, '{1,1}', 100);
INSERT INTO price VALUES (66, '{1,2}', 200);
Need to get the sum value of all the products from table food. Please help make a sql query.
ANSWER: {1} - Apple - 800 (500+100+200)
foodtable. Does this mean "banana" has two different ids? And why does Orange have the same IDs as Apple? And what does it mean that "Orange" and "Banana" have two ids. What is the primary key of thefoodtable? The model and the data do not make any sense to me.