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!

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.