Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I hope this helps!</p> <p>Two Major ways:</p> <p>1- Small, easy to understand and easy for later changes</p> <p>2- Big, more complicated and hard to change!</p> <p>Let's try easy one first:</p> <pre><code>create view stats as YOUR_FIRST_BIG_QUERY_HERE; </code></pre> <p>now easy way to go:</p> <pre><code>select USER_ID,sum(wins),sum(ties), sum(loses) from stats /*this is our new created view*/ group by USER_ID; </code></pre> <p>it was easy!</p> <p>Now the though one!!</p> <p>Let's use the sub-query here:</p> <pre><code>select USER_ID,sum(wins),sum(ties), sum(loses) from (SELECT IF((player1_choice + 1) % 3 + 1 = player2_choice + 0 AND player1_user_id = rps_user.user_id OR (player2_choice + 1) % 3 + 1 = player1_choice + 0 AND player2_user_id = rps_user.user_id, 1, 0) AS win, IF(player1_choice = player2_choice, 1, 0) as tie, IF(player1_choice % 3 + 1 = player2_choice + 0 AND player1_user_id = rps_user.user_id OR player2_choice % 3 + 1 = player1_choice + 0 AND player2_user_id = rps_user.user_id, 1, 0) AS loss FROM rps_game INNER JOIN rps_session USING (session_id) INNER JOIN rps_user ON rps_session.player1_user_id = rps_user.user_id OR rps_session.player2_user_id = rps_user.user_id WHERE player1_choice IS NOT NULL AND player2_choice IS NOT NULL) group by USER_ID; </code></pre> <p>actually both of these two are the same!</p> <p>but I want to show second one ugly because it is much better to use views!</p> <p>I'm a oracle fan, hope syntax is correct in your Environment.</p> <p>Good luck.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload