php - MySQL Math on "join" function -


not sure how explain this, but, have 2 tables, , need math on values. having issues other addition (which automatically).

this mysql statement using.

select snippet_id, count(snippet_id) cnt snippets_likes join snippets_engagement on snippet_id = snippets_engagement.snip_id group snippet_id order cnt desc 

this statements pulls total number of likes + engagements.

however, want have equal likes + ( engagements/1000 ).

table construction

create table  `iotunes`.`snippets_engagement` (   `id` int(10) unsigned not null auto_increment,   `snip_id` int(10) unsigned not null default '0',   `artist_id` int(10) unsigned not null default '0',   `snip_timestamp` timestamp not null default current_timestamp,   `engagement_type` int(10) unsigned not null default '0',   primary key (`id`) ) engine=innodb auto_increment=6694 default charset=latin1;  create table  `iotunes`.`snippets_likes` (   `id` int(10) unsigned not null auto_increment,   `snippet_id` int(10) unsigned not null default '0',   `artist_id` int(10) unsigned not null default '0',   `snippet_like` int(10) unsigned not null default '0',   primary key (`id`) ) engine=innodb auto_increment=197 default charset=latin1; 

i have tried many different formulas, but, cannot work. pointers?

try statement:

select snippet_id, sum(cnt) cnt (    select snippet_id, count(1) cnt    snippets_likes     group snippet_id    union    select snippet_id, count(1)/1000 cnt    snippets_engagement     group snippet_id ) subq group snippet_id order cnt desc 

or if insist on join...

select sl.snippet_id, count(distinct sl.id) + count(distinct se.id)/1000 cnt snippets_likes sl join snippets_engagement se  on sl.snippet_id = se.snip_id group snippet_id order cnt desc 

i wouldn't recommend join though, you'll values "snippets" have @ least 1 "like" , 1 "engagement".


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -