mysql - Dividing count(*) sql statements to get ratios -
i have table 1 column web site name , 1 column action can done website. so, 1 row -
site   action -----  ------ yahoo  view    i trying find ratio of 1 action another. know how can entire table statement below, wondering if there statement write return ratios on site-level. yahoo 15%, google 20%, etc, listed out wouldn't have have different statement each site. thanks
select (select count(*) practice  action='like') / (select count(*)  practice action='view') dual;      
the keyword need group by. not knowing field table names little hard this
select       sum(case when action = 'like' 1 else 0 end) countlike,      sum(case when action = 'view' 1 else 0 end) countview,       (sum(case when action = 'like' 1 else 0 end)/count(action)) ratioliketotal ,      (sum(case when action = 'view' 1 else 0 end)/count(action)) ratioviewtotal ,      site       tbllinks  group    site   with breakdown site can calculate ratios in app or against total of hits.
Comments
Post a Comment