SQL query problem
-
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
-
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
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 descI 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!!
-
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 descI 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!!
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
-
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