newphpcoder Posted March 27, 2012 Share Posted March 27, 2012 Hi I got an error: Error Code : 1064 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 '), NOW()),' day(s) ', TIMESTAMPDIFF(HOUR, AVG(chemicalweighing_dateEntry), NOW()' at line 1 (0 ms taken) from my query: SELECT (concat(TIMESTAMPDIFF(DAY, AVG(), NOW()),' day(s) ', TIMESTAMPDIFF(HOUR, AVG(chemicalweighing_dateEntry), NOW()) - (TIMESTAMPDIFF(DAY, AVG(chemicalweighing_dateEntry), NOW()) * 24), ' hr(s) ago')) AS AGE FROM kanban_data GROUP BY chemicalweighing_dateEntry; I just need to get the aging. I attach the data of chemicalweighing_dateEntry . Thank you. Link to comment Share on other sites More sharing options...
requinix Posted March 27, 2012 Share Posted March 27, 2012 AVG of what? Link to comment Share on other sites More sharing options...
cpd Posted March 27, 2012 Share Posted March 27, 2012 Just to reiterate what requinix is saying. SELECT (concat(TIMESTAMPDIFF(DAY, AVG(), NOW()),' day(s) ' Link to comment Share on other sites More sharing options...
newphpcoder Posted March 29, 2012 Author Share Posted March 29, 2012 I just want to get is the aging of all dateentry in chemicalweighing. Thank you Link to comment Share on other sites More sharing options...
newphpcoder Posted March 29, 2012 Author Share Posted March 29, 2012 I revised my code to this: SELECT (concat(TIMESTAMPDIFF(DAY, AVG(chemicalweighing_dateEntry), NOW()),' day(s) ', TIMESTAMPDIFF(HOUR, AVG(chemicalweighing_dateEntry), NOW()) - (TIMESTAMPDIFF(DAY, AVG(chemicalweighing_dateEntry), NOW()) * 24), ' hr(s) ago')) AS AGE FROM kanban_data GROUP BY chemicalweighing_dateEntry; and i also try instead of AVG I use MAX SELECT (concat(TIMESTAMPDIFF(DAY, MAX(chemicalweighing_dateEntry), NOW()),' day(s) ', TIMESTAMPDIFF(HOUR, MAX(chemicalweighing_dateEntry), NOW()) - (TIMESTAMPDIFF(DAY, MAX(chemicalweighing_dateEntry), NOW()) * 24), ' hr(s) ago')) AS AGE FROM kanban_data GROUP BY chemicalweighing_dateEntry; and they are same output. and I attach the result. Now I want to know how can I can the sum of ALL this data. I need a query again to get the sum or I need output is : 67 day(s) 200 hr(s) ago. Thank you so much Link to comment Share on other sites More sharing options...
AyKay47 Posted March 29, 2012 Share Posted March 29, 2012 So use SUM()..? Link to comment Share on other sites More sharing options...
newphpcoder Posted March 29, 2012 Author Share Posted March 29, 2012 how? thank you Link to comment Share on other sites More sharing options...
newphpcoder Posted March 29, 2012 Author Share Posted March 29, 2012 I tried this: SELECT(concat(SUM(TIMESTAMPDIFF(DAY, chemicalweighing_dateEntry, NOW())),' day(s) '), SUM(TIMESTAMPDIFF(HOUR, chemicalweighing_dateEntry, NOW()) - (TIMESTAMPDIFF(DAY, chemicalweighing_dateEntry, NOW()) * 24), ' hr(s) ago')) AS AGE FROM kanban_data; and I got an error: Error Code : 1241 Operand should contain 1 column(s) (0 ms taken) I can't figured out where I am wrong Thank you Link to comment Share on other sites More sharing options...
fenway Posted March 31, 2012 Share Posted March 31, 2012 You're working up to a ban with all of this cross-posting. Link to comment Share on other sites More sharing options...
Recommended Posts