php - Amending a join query to add a new value to a query -


the query below works well. pulls information 3 mysql tables: login, submission, , comment.

it creates value called totalscore2 based on calculation of values pulled these 3 tables.

the mysql tables "comment" , "submission" both have following fields:

loginid submissionid 

in table "submission," each "submissionid" has 1 entry/row, , 1 "loginid" associated it.

in table "comment," field "submissionid" have several entries/rows, , associated multiple "loginid"s.

each time 1 of "submissionid"s in "comment" associated same "loginid" has in table "submission," add factor equation below. multiple instances times (-10).

how this?

thanks in advance,

john

$sqlstr2 = "select      l.loginid,      l.username,      l.created,     datediff(now(), l.created) + coalesce(s.total, 0) * 5 + coalesce(scs.total, 0) * 10 + coalesce(c.total, 0) totalscore2 login l     left join (     select loginid, count(1) total      submission      group loginid ) s on l.loginid = s.loginid left join (     select loginid, count(1) total      comment      group loginid ) c on l.loginid = c.loginid left join (     select s2.loginid, count(1) total      submission s2     inner join comment c2     on c2.submissionid = s2.submissionid     group s2.loginid ) scs on scs.loginid = l.loginid group l.loginid order totalscore2 desc  limit 25"; 

    $sqlstr3 = "select          l.loginid,          l.username,       l.created,      datediff(now(), l.created) + coalesce(s.total, 0) * 5 + coalesce(scs.total, 0) * 10 - coalesce(nscs.total, 0) * 10 + coalesce(c.total, 0) totalscore2     login l         left join (         select loginid, count(1) total          submission          group loginid     ) s on l.loginid = s.loginid     left join (         select loginid, count(1) total          comment          group loginid     ) c on l.loginid = c.loginid      left join (         select s2.loginid, count(1) total          submission s2         inner join comment c2         on c2.submissionid = s2.submissionid         group s2.loginid     ) scs on scs.loginid = l.loginid       left join (         select s2.loginid, count(1) total          submission s2         inner join comment c2         on c2.submissionid = s2.submissionid      , c2.loginid = s2.loginid         group s2.loginid     ) nscs on nscs.loginid = l.loginid        group l.loginid     order totalscore2 desc      limit 25"; 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -