MySQL Forums
Forum List  »  General

Re: Get the Maximum (Max) value BUT separate for EACH item
Posted by: Peter Brawley
Date: February 10, 2019 08:09AM

You've not revealed how sales numbers are stored in your json column, but to get max values from them you need to retrieve numeric values, withou $ or comma chars.

And to combine sales figures from one table with names from another, you need Join...On... synax, see the manual page for Join.

About max per name, read about Group By and aggregation in the manual. To get the mex of col b per column a in table t we write: select a,max(b) from t group by a.

So you'd get the raw values with ...

select b.name, json_extract (a.attributes, '$ .sale'), '.', ',') as sales
from tc_sales a
join tc_sellers b on ...
where fixtime between '2018-09-01' and '2018-09-30'

... where you'll need to supply the On clause details, then aggregate and gussy it up as desired in an outer query ...

select name, replace( max(sales), '.', ',' ) as max_sales
from (
  select b.name, json_extract (a.attributes, '$ .sale'), '.', ',') as sales
  from tc_sales a 
  join tc_sellers b on ...
  where fixtime between '2018-09-01' and '2018-09-30' 
) x 
group by nam;

Options: ReplyQuote


Subject
Written By
Posted
Re: Get the Maximum (Max) value BUT separate for EACH item
February 10, 2019 08:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.