Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

mysql error: for the right syntax to use near ')

mysql syntax

  • Please log in to reply
5 replies to this topic

#1 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 26 March 2012 - 11:56 PM

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.


Thank you.

Attached Thumbnails

  • chemicalweighing_dateEntry.jpg

  • 0

#2 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 28 March 2012 - 03:09 AM

It probably doesn't like you calculating the average of nothing:
[LEFT][COLOR=#333333]DAY, [B]AVG()[/B], NOW()[/COLOR][/LEFT]

  • 0

#3 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 28 March 2012 - 04:21 PM

So what should be my code?

Thank you
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 28 March 2012 - 04:32 PM

It depends on what you want to take the average of.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 28 March 2012 - 04:32 PM

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

Attached Thumbnails

  • aging.jpg

  • 0

#6 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 28 March 2012 - 07:18 PM

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
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download