azlan3522 Posted July 24, 2013 Share Posted July 24, 2013 (edited) I have an SQL query that inserts data into my database. I'm trying to use the mysql function STDDEV_SAMP(), and it doesn't appear to work. Here it is: $query = "INSERT INTO table (percent, deviation) VALUES ($percent, STDDEV_SAMP(percent))"; I've searched around to see if anyone has used Aggregate functions in an INSERT INTO query, but I haven't found anything that has helped me yet. Note that this is sample code that I'm using to display my problem. Edited July 24, 2013 by azlan3522 Quote Link to comment https://forums.phpfreaks.com/topic/280448-mysql-query-help/ Share on other sites More sharing options...
Muddy_Funster Posted July 24, 2013 Share Posted July 24, 2013 shouldn't it be : $query = "INSERT INTO table (percent, deviation) VALUES ($percent, STDDEV_SAMP($percent))"; with $percent sent to both values? Quote Link to comment https://forums.phpfreaks.com/topic/280448-mysql-query-help/#findComment-1441903 Share on other sites More sharing options...
azlan3522 Posted July 24, 2013 Author Share Posted July 24, 2013 That was demo code, but yes that's what I meant to say. Thanks for the clarification. Quote Link to comment https://forums.phpfreaks.com/topic/280448-mysql-query-help/#findComment-1441952 Share on other sites More sharing options...
AbraCadaver Posted July 24, 2013 Share Posted July 24, 2013 Why even store STDDEV_SAMP($percent) as it is calculated from $percent? Just store $percent and calculate when you need it. Quote Link to comment https://forums.phpfreaks.com/topic/280448-mysql-query-help/#findComment-1441959 Share on other sites More sharing options...
Psycho Posted July 24, 2013 Share Posted July 24, 2013 << Moving to MySQL Forum >> What you are doing doesn't make sense, so I'm not sure what you are trying to accomplish. The STDDEV_SAMP() is a GROUP_BY (aggregate) function which assumes a list of values. Since $percent is also stored into the field 'percent', I assume it is a single value. So, there will not be a standard deviation. Please explain what you are trying to do and we might be able to help. Quote Link to comment https://forums.phpfreaks.com/topic/280448-mysql-query-help/#findComment-1441960 Share on other sites More sharing options...
azlan3522 Posted July 30, 2013 Author Share Posted July 30, 2013 I'm sorry for the late response. I figured out the solution. Thank you all for your help, and sorry for the waste of time. Quote Link to comment https://forums.phpfreaks.com/topic/280448-mysql-query-help/#findComment-1442682 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.