Laetis Laetis -4 years ago 54
MySQL Question

Proper use of mysql sum function

I have the following table:

Field | Type | Null | Key | Default | Extra |
+-----------------+----------------------+------+-----+---------+-------+
| SMILES | char(200) | NO | PRI | | |
| ConfRank | smallint(5) unsigned | NO | | NULL | |
| CompTime | double | YES | | NULL | |


I want to get the total CompTime for a specific SMILES (meaning Comptime are added for al confrank of a specific smiles).

I tried the following:

SELECT SMILES,(SUM(CompTime)) From GeoAndEnergies GROUP BY ConfRank WHERE SMILES='C';


And received this error:


ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '
WHERE SMILES='C'
' at line 1


I also tried:

SELECT SMILES,(SUM(CompTime)) From GeoAndEnergies GROUP BY ConfRank WHERE SMILES='C' GROUPBY ConfRank ;


And received another error:


ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '
WHERE SMILES='C' GROUPBY ConfRank
' at line 1


What would be the correct syntax?

Answer Source

try the following

 SELECT SMILES,(SUM(CompTime)) From GeoAndEnergies WHERE  SMILES='C' GROUP BY  ConfRank;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download