LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-20-2018, 12:03 PM   #1
pradeepspa
Member
 
Registered: Oct 2015
Posts: 79

Rep: Reputation: Disabled
SQl-Unique-Query


I am trying to do a query against the INFLUX-DB to get unique values.Below is the query I use,

Code:
select host AS Host,(value/100) AS Load from metrics  where time > now() - 1h and command='Check_load_current' and value>4000;
The output for the query is,

Quote:
time Host Load
---- ---- ----
1529508443000000000 host-1 42.72
1529508609000000000 host-5 53.94
1529508856000000000 host-1 40.37
1529508913000000000 host-2 41.02
1529508937000000000 host-1 44.49

What I actually want is the unique "Host" values. For example I want "host-1" as a output repeated only once(latest value) eventhough the load values are different.How can I achieve this? Any help would be much helpful.
 
Old 06-20-2018, 12:08 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Please look at how to use the ORDER-BY clause...and maybe LAST...
 
1 members found this post helpful.
Old 06-20-2018, 12:12 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by pradeepspa View Post
I am trying to do a query against the INFLUX-DB to get unique values.Below is the query I use,
Code:
select host AS Host,(value/100) AS Load from metrics  where time > now() - 1h and command='Check_load_current' and value>4000;
The output for the query is
Code:
time Host Load
---- ---- ----
1529508443000000000 host-1 42.72
1529508609000000000 host-5 53.94
1529508856000000000 host-1 40.37
1529508913000000000 host-2 41.02
1529508937000000000 host-1 44.49
What I actually want is the unique "Host" values. For example I want "host-1" as a output repeated only once(latest value) eventhough the load values are different.How can I achieve this? Any help would be much helpful.
As with many of your previous threads, you are providing next to no useful information. You don't tell us anything about the structure of that table, version/distro of Linux, version of MySQL, etc. The query you posted doesn't match the output (you select two columns, but post 3).

Read the MySQL documentation on both the DISTINCT and GROUP BY directives.
 
Old 06-20-2018, 12:51 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,224

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by scasey View Post
Please look at how to use the ORDER-BY clause...and maybe LAST...
And GROUP BY and HAVING.
 
1 members found this post helpful.
Old 06-20-2018, 03:36 PM   #5
pradeepspa
Member
 
Registered: Oct 2015
Posts: 79

Original Poster
Rep: Reputation: Disabled
Apologize for not providing essential info. I am running on centos-7 and this query is on INFLUX-DB. Since its similar to sql query i assumed both uses similar pattern.
 
Old 06-20-2018, 03:45 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Saw the name of the database engine in your OP...I also presume the syntax is similar (most ansi SQL is similar). Doesn’t really change anything: you need to learn what the suggested modifiers do and how to apply them to your selection. You’ll need to study the documentation for your database. We can’t do that for you.

Last edited by scasey; 06-20-2018 at 03:47 PM.
 
Old 06-20-2018, 03:51 PM   #7
pradeepspa
Member
 
Registered: Oct 2015
Posts: 79

Original Poster
Rep: Reputation: Disabled
Thank you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL query manolakis Programming 9 06-29-2017 11:50 AM
sql query amer99 Programming 3 05-27-2012 09:24 PM
sql query aocferreira Programming 2 05-13-2011 03:58 AM
sql query help struct Programming 2 10-27-2010 12:29 AM
BASH query to find unique Usernames basildon Linux - Newbie 9 09-05-2008 03:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration