Help needed with subquery -
12-16-2008
, 12:38 PM
CREATE TABLE "o"."tb_main" (
"cust_id" VARCHAR,
"order_no" VARCHAR
) WITH OIDS;
CREATE TABLE "o"."tb_detail" (
"order_no" VARCHAR,
"item_name" INTEGER,
"price" INTEGER
) WITH OIDS;
I'm trying to query order_no rows for a specific cust_id from the main
table, but on the same row, I would also like to show all item_name COUNT
for each order, where price > 0.
order_no | item_name
----------------------
1 | 15
2 | 7
Here is what I tried:
SELECT * FROM "o"."tb_main"
LEFT JOIN (SELECT COUNT(item_name) FROM "o"."tb_detail" WHERE price > 0 )
AS pcount
ON tb_main.order_no = tb_detaill.order_no
WHERE cust_id=1;
Obviously above doesn't work but cannot figure out the syntax.
Can anyone help?
Thanks |