2

Sql select the last value

 2 years ago
source link: https://www.codesd.com/item/sql-select-the-last-value.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Sql select the last value

advertisements

I have the following SQL statement

SELECT [Motor]
      ,[Time]
  FROM [logger].[dbo].[motor]
  WHERE day([Time]) = day(getdate())
  ORDER BY [TIME]

This is a very basic table that gives me the status of a motor at a given time.

All I want is a select statement that will give me the latest result if possible. I can get it so it gives all of today's results but if I could get it so that it only displays the latest result that would be great.


SELECT TOP(1) [Motor] ,[Time]
FROM [logger].[dbo].[motor]
WHERE day([Time]) = day(getdate())
ORDER BY [TIME] DESC

Tags sql

Related Articles

Select the last value in multiple groups (SQL Server)

I'm unsure how to both group and select the last value from within that group and could use some expertise. This simple table (snippet of table below) holds the values of various timestamps for when a series of URLs I'm checking don't respond correct

Java JComboBox Select the last value

I have a JComboBox in which I have given the user the possibility to add a new value into that JComboBox, when they have added that value I want it so that value is now selected. It automatically always sets the current selection to the first value i

Use the stored procedure to select the last value of the element

i am trying to select the last record value from my database by using stored procedure, to do this i set my @UPID parameter as SCORE_IDENTITY(), but there are no output result as all after i execute my stored procedure CREATE PROCEDURE [dbo].[spAudit

(SQL) SELECT the mean value with the interval

Sample data: I want to select the average value every 5 minutes, for example. The result should be a list like this: 3 8 The functions for this should be: AVG(VALUE), DATEDIFF(datepart, startdate, enddate) with datepart=minute and/or DATEADD (datepar

SQL - Select the largest value in a row

I seem to be stuck on this and can't find a solution having had a look around. I have an SQL table who's first row looks something like this: Name Val1 Val2 Val3 John 1000 2000 3000 What I need to do is Select the largest value within this row i.e. 3

SQL Select the last table result where keyword = and competitor =

I have two tables as such: tablename: input_keywords Cols: keyword, last_check, pages_deep, check_freq_days tablename: rank_result Cols: keyword, result_url, position, last_check, competitor input_keywords.keyword is unique, so that we don't look for

Selecting the last value of a column

I have a spreadsheet with some values in column G. Some cells are empty in between, and I need to get the last value from that column into another cell. Something like: =LAST(G2:G9999) except that LAST isn't a function.So this solution takes a string

SQL: Select the lowest value that does not already exist

In TableA I have an int column. Is it possible using only a select statement to select the minimum value in the column that DOES NOT EXIST and is greater then 0? For example, if the col has the values 1,2,9 the select statement will return 3. If the

query mysql to select the last value in column 1 and the maximum value of the last 5 rows in column 2

How can I select last value in Column 1 and Max value from last 5 rows in Column 2 and union them together? For a table like this: Column_1 Column_2 Timestamp 5 3000 2013-07-31 12:00:00 3 1000 2013-07-31 11:00:00 6 2000 2013-07-31 10:00:00 2 4000 201

Select the last value in a month for all given credentials

I have 2 tables, one containing meter IDs, and another containing measurements for some of the meters in the first table. This is the table structure: MeterConfig: MeterID (int) MeterNumber (char[16]) Type (char[25]) Readings: MeterID (int) Date (dat

MySQL - Select the last value for the last 7 days using multiple tables

Here's my current database: TABLE profileData +---------------------------+ | profileID | name | +----+----------------------+ | 1 | Stackoverflow | | 2 | Stackexchange | | 3 | Askubuntu | +-----------+---------------+ TABLE stats +----+-----------+-

Select the last value of each column, with a single query

Having the following data (blank means NULL): ID ColA ColB ColC 1 15 20 2 11 4 3 3 How can I get the last not-NULL values of each column in a single query? So the resulting for the given data would be: ColA ColB ColC 11 3 20 I have not found much, th

SQL selects the minimum value in a subquery when the exact value is unknown

I have an SQL query that is meant to select a list of things from different tables using a subquery. I am meant to find those things with the lowest value in a particular column. This is the query that i currently have. I know the minimum rate is 350

Sql - select the different value of a nested query from the maximum value

Trying to obtain the Userid value in a row where the max(DateOccurred) was found. I'm getting lost in all these sub-queries. I'm using SQL Server 2008. NOTE: Need to return single value since part of another larger query in a SELECT statement. Exampl

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK