mysql - How to check in SQL if particular value of a column is appearing more than once -
i trying problem came across have sum sales of particular region , 1 more column needs created result name stores can tell whether particular store in region (east, west, north, , south) or not.
in mysql, can achieve result byleft join-ing store_info geography table , group by on column region below. don't need sum separately case again.
select g.region, sum(s.sales) sales, case when sales > 0 'y' else 'n' end stores geography g left join store_info s on s.sn = g.sn group g.region order 2 desc result
region sales stores ---------------------- west 2050 y east 700 y south null n north null n you can check demo here
hope help.
wiki

Comments
Post a Comment