Good morning Stack Overflow I have a project in ASP.Net (C#) connected to a game database. I have a
String connStringPlayer = System.Configuration.ConfigurationManager.ConnectionStrings["PlayerDB"].ToString();
conn = new MySql.Data.MySqlClient.MySqlConnection(connStringPlayer);
queryStr = "SELECT playtime FROM player.player WHERE account_id='" + AccountId + "' LIMIT 5";
cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn);
Int32 countpt = (Int32)cmd.ExecuteScalar();
String playcount = countpt.ToString();
AccountInfoTotalGameMinuetsValue.Text = playcount;
SUM is what you are looking for
Returns the sum of expr. If the return set has no rows, SUM() returns NULL. The DISTINCT keyword can be used to sum only the distinct values of expr.
SUM() returns NULL if there were no matching rows.
So the following query Will give you the totals for all the players
SELECT account_id, SUM(playtime) FROM player.player GROUP BY account_id;
if you want the information for just one player
SELECT account_id, SUM(playtime) FROM player.player WHERE account_id = some_id GROUP BY account_id;