mysql - Union Two SQL Queries -


i have query

select o.product_id,        p.name,        count(o.product_id) total_products_sold,        (select count(o.id)         ebay.`order` o) total_orders ebay.`order` o inner join product p on o.product_id = p.id group o.product_id 

the total_orders rerun when executed each not want. i

question:

i want total_orders combines every result set outer query.

i tried return 1 row

select tps.product_id,        tps.name,        tps.total_products_sold,        count(oo.id) total_orders ebay.`order` oo inner join   ( select o.id,            o.product_id,            p.name,            count(o.product_id) total_products_sold    ebay.`order` o    inner join product p on o.product_id = p.id    group o.product_id ) tps on oo.product_id = tps.product_id 

any better solution ?

thanks.

select  tps.product_id,         tps.name,         tps.total_products_sold,         s.total_orders    ebay.`order` oo         inner join         (              select  o.id,                     o.product_id,                     p.name,                     count(o.product_id) total_products_sold                ebay.`order` o                     inner join product p                          on o.product_id = p.id             group   o.product_id          ) tps on oo.product_id = tps.product_id         cross join         (             select  count(id) total_orders                ebay.`order`         ) s 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -