Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL query problem

SQL query problem

Scheduled Pinned Locked Moved Database
databasehelpdata-structuresquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    josephong
    wrote on last edited by
    #1

    Hi all, I'm plotting a graph using values from the database which i have stored inside. Below is the sentence i use to extract my x & y axis values. select temp,result_time from mts300_results where nodeid=5 order by result_time like '%:00:%' desc limit 10; where temp = x axis result_time = y axis wanting the graph to plot a point every hour in the result time(yyyy-mm-dd hh-mm-ss)and where showing the lastest result. But the graph output time and date is not desc and it all jumble up. can any one help me to correct my statement? Any help will be appreciated. Thanks & Regards Joseph

    _ 1 Reply Last reply
    0
    • J josephong

      Hi all, I'm plotting a graph using values from the database which i have stored inside. Below is the sentence i use to extract my x & y axis values. select temp,result_time from mts300_results where nodeid=5 order by result_time like '%:00:%' desc limit 10; where temp = x axis result_time = y axis wanting the graph to plot a point every hour in the result time(yyyy-mm-dd hh-mm-ss)and where showing the lastest result. But the graph output time and date is not desc and it all jumble up. can any one help me to correct my statement? Any help will be appreciated. Thanks & Regards Joseph

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      josephong wrote:

      select temp,result_time from mts300_results where nodeid=5 order by result_time like '%:00:%' desc limit 10;

      Take the like out of the order by clause and put it into the where, like this:

      select top 10 temp,result_time
      from mts300_results
      where nodeid=5
      and result_time like '%:00:%'
      order by result_time desc

      I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! If you like cars, check out the Booger Mobile blog | If you feel generous - make a donation to Camp Quality!!

      J 1 Reply Last reply
      0
      • _ _Damian S_

        josephong wrote:

        select temp,result_time from mts300_results where nodeid=5 order by result_time like '%:00:%' desc limit 10;

        Take the like out of the order by clause and put it into the where, like this:

        select top 10 temp,result_time
        from mts300_results
        where nodeid=5
        and result_time like '%:00:%'
        order by result_time desc

        I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! If you like cars, check out the Booger Mobile blog | If you feel generous - make a donation to Camp Quality!!

        J Offline
        J Offline
        josephong
        wrote on last edited by
        #3

        i extract values from POSTGREsql and its giving error when i use select temp,result_time from mts300_results where nodeid=5 order by result_time like '%:00:%' desc limit 10; Error: DBD::Pg::st execute failed: ERROR: syntax error at or near "10" LINE 1: select top 10 temp,result_time from mts300_results where nod... ^ at C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/asd.cgi line 19. My code: my $dbh = DBI->connect('dbi:Pg:dbname=task;host=localhost', 'tele', 'tiny', { RaiseError => 1, AutoCommit => 0}); my $sql = qq/select top 10 temp,result_time from mts300_results where nodeid=? and result_time like '%:00:%' order by result_time desc/; my $sth = $dbh->prepare($sql) or die $!; $sth->execute(5); Thanks & Regards Joseph

        L 1 Reply Last reply
        0
        • J josephong

          i extract values from POSTGREsql and its giving error when i use select temp,result_time from mts300_results where nodeid=5 order by result_time like '%:00:%' desc limit 10; Error: DBD::Pg::st execute failed: ERROR: syntax error at or near "10" LINE 1: select top 10 temp,result_time from mts300_results where nod... ^ at C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/asd.cgi line 19. My code: my $dbh = DBI->connect('dbi:Pg:dbname=task;host=localhost', 'tele', 'tiny', { RaiseError => 1, AutoCommit => 0}); my $sql = qq/select top 10 temp,result_time from mts300_results where nodeid=? and result_time like '%:00:%' order by result_time desc/; my $sth = $dbh->prepare($sql) or die $!; $sth->execute(5); Thanks & Regards Joseph

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Please read "_Damian S_"'s post again, it pretty much has the solution.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups