u214 Posted September 9, 2012 Share Posted September 9, 2012 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! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 9, 2012 Share Posted September 9, 2012 The error in your current query is because the FROM table_name is not in the correct location. Quote Link to comment Share on other sites More sharing options...
elite311 Posted September 9, 2012 Share Posted September 9, 2012 Are all the values you want to sum contained in the users table? or are you storing the users in 1 table and the values in other tables? Quote Link to comment Share on other sites More sharing options...
u214 Posted September 9, 2012 Author Share Posted September 9, 2012 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 9, 2012 Share Posted September 9, 2012 Also, if the "FROM".. is in the wrong place, mind explaining / pointing out where it should be? Thanks. SELECT ... FROM ... WHERE ... Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 9, 2012 Share Posted September 9, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.