mysql retrieving all rows while also using summaries -


i have query:

select name, apn, bpn, count(apn), min(acost), min(bcost), ceil(avg(aqty)),  max(aqty), sum(bshipped),  concat(truncate((avg(aresale)-avg(acost))/avg(aresale),2) * 100,'%'), code (select name, apn, bpn, acost, aqty, code     table_1     customer = '12345' ,     adate >= '2013-01-01' ,     adate <= '2015-12-12') qh inner join (select cpn, bcost, bresale, bshipped table_2  customer = '12345') ih on qh.apn = ih.cpn bshipped > 0 group qh.apn; 

what need out of each row output, can't figure out how that. right now, i'm getting this:

name   |   apn  |  bpn   |  apn count asdf       001     555      3  /*summary of apn 001*/ qere       002     865      1  /*summary of apn 002*/ rtrt       003     123      2  /*summary of apn 003*/ 

because of group by, i'm getting summary of qh.apn, if don't use group by statement, 1 line in result.

i looking have apn count column, while @ same time showing rows - not having values summarized. this:

name   |   apn  |  bpn   |  apn count asdf       001     555      3  /*individual record, count too*/ asdf       001     862      3  /*individual record, count too*/ asdf       001     999      3  /*individual record, count too*/ qere       002     865      1  /*individual record, count too*/ rtrt       003     123      2  /*individual record, count too*/ rtrt       003     456      2  /*individual record, count too*/ 

i need see each individual record makes apn count column because need see each bpn, not 1 summary row. writing group by right because seeing summarized data better nothing, , because don't know correct syntax use here result want.

join table 1 aggregate query subquery.

select t1.name, t1.apn, t1.bpn, t1.code, t2.* table_1 t1 join (     select apn, count(apn) apn_count, min(acost) min_acost, min(bcost) min_bcost, ceil(avg(aqty)) avgqty,      max(aqty) maxqty, sum(bshipped) sum_bshipped,      concat(truncate((avg(aresale)-avg(acost))/avg(aresale),2) * 100,'%') avg_margin     (select name, apn, bpn, acost, aqty, code         table_1         customer = '12345' ,         adate >= '2013-01-01' ,         adate <= '2015-12-12') qh     inner join (select cpn, bcost, bresale, bshipped table_2      customer = '12345') ih     on qh.apn = ih.cpn     bshipped > 0     group qh.apn) t2 on t1.apn = t2.apn 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -