SQL query with 2 joins and count -


I have spent the last 8 hours trying to work this SQL query and I can not do it. I am not very experienced, but I am trying to improve it.

I have 2 tables:

  table cheaper column: id | User ID Made Off | Winner | Cancel 1 | 7962290564 | 2014-07-26 20:32:22 | 2014-07-26 20:32:22 | 7962290566 | Zero 2 7962290565 | 2014-07-26 20:32:22 | 2014-07-26 20:32:22 | 7962290567 | Zero 3 7962290566 | 2014-07-26 20:32:22 | 2014-07-26 20:32:22 | 7962290567 | Faucet 4 7962290566 | 2014-07-26 20:32:22 | 0000-00-00 00:00:00 | Faucet Faucet table user column: id | Steamid | Joined Role | Name 1 7962290564 | 2014-07-26 20:32:22 | 1 | User A 2 | 7962290565 | 2014-07-26 20:32:22 | 4 | User B3 | 7962290566 | 2014-07-26 20:32:22 | 4 | User C4 7962290567 | 2014-07-26 20:32:22 | 4 | User D5 | 7962290568 | 2014-07-26 20:32:22 | 4 | User E6 | 7962290569 | 2014-07-26 20:32:22 | 5 | User F  

What I am doing after the same result, how many times someone has an IDE in his purview. The user and the number of times someone has the id in his cleaning. the winner . Apart from this there are some such elements to filter out unwanted results.

Something like this:

  select user.steamid, user.name, count (giveaway.userid) nrgiven, count (cheap.exired), user to user 1 and 4 more between user.loud. And is canceled. Cancel and cheap Closed is done by the NUL group user. User.Stimmed = Cleanness for the built-in tables. User user.Stimmed = Giveaway.winnerid  

should be the result:

  volatile | Name | NRWN | Nrgiven 7962290564 | User A | 0 | 1 79622 9 0565. User b 0 | 1 7962290566 | User C 1 | 2 7962290567 | User D | 2 | 0 7962290568 | User e 0 | 0  

Here are some examples of what I have tried, but none of them counts well.

  SELECT user.steamid, user.name, Count (giveaway.userid) Users can be included in the cleaning. Oostamid = cleanliness Between user and user And 4 And 4 more cheaper. Is closed. Faucet and debtor are not. Use by Null Group by user.stimid ORDER BY nrgiven DESC; --- Select user from user.roleid, user.steamid, user.name, a.nrgiven, b.nrwon, user (except the selection number (user.steamid) user, except on the user, in the white user. Asteamid = giveaway.userid), (Selection Number (user.steamid) give the user cheaper on the left user than the nrwon. Ostimed = cheap. Winner) b; --- Select from the user user.steamid, user.name, a.nrwon user, (white count) (Cheaper.Vinirid) give the user cheaper to clean the user from scratch. Winnerid = user.steamid user WHERE user 1 and 4 Between and 4 and cheaper. Stop! = 0 and cheaper. The winner is not by the user group. User by a group by Steamid DESC;  

I was able to obtain your expected result table from that dataset with the following query :

Select
  as the user.steamid, user.name, COALESCE (winners.Nrwon, 0) nrwon, COALESCE (nrgiveaways.nrgiven, 0) as nrgiven, from user LEFT Join (SELECT winnerid, WINER WHERE Winner, not a victorious winner won by winning, as giving NORN as COUNT (*)) as the winner on the winner. Winner = User.Stimid Join Left (Select UserAd, User ID by Group Dispatched from Encryption as COUNT (*)) nrgiveaways.userid on nrgiveaways = User.steamid Role in WHERE (1,2,3,4)  

The winners and giveaways are found in their own tables and then added to the user table using the left join.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -