Jump to content

SELECT SUM and WHERE / Sum of rows for multiple tables in 1 query.


u214

Recommended Posts

Hi, so this is my code right now:

SELECT SUM(Kills) AS g_killz, SUM(Deaths) AS g_deathz, SUM(Level) AS g_admins WHERE Level > 0 FROM Users

The Level part is messing the whole query. How would I get the sum of Level greater than 0.

 

------------

How can I get the SUM of rows from multiple tables in 1 query? Pretty sure a query per table isn't the best thing to do!

Link to comment
Share on other sites

Alright, for the first question:

 

Kills, Deaths, and Level are all stored in the User's table. I successfully got the Kills and Deaths, but can't get the sum of Levels above 0. Also, if the "FROM".. is in the wrong place, mind explaining / pointing out where it should be? Thanks.

 

Second question:

 

Let's say I have 5 tables. I want to get the # of rows of each table using 1 query.

 

Hope that clears some misunderstandings.

Link to comment
Share on other sites

Let's say I have 5 tables.

 

Since you haven't shown any information about these multiple tables, it's not possible to provide a direct answer. If the tables are related, when you write a query using JOINs, you can sum information the same as if you were querying one table.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.