Hi,
I have a Problem I don't get resolved.
First to the conditions.
My table Looks like this:
Table
---------------------------------------------------
(IDENTITY) ID | bigint
(PK) InverterID | bigint
(PK) TimeStamp | datetime
DayYield | decimal
Error | varchar
Here the reproduce script:
CREATE TABLE [dbo].[InverterData]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [InverterID] [bigint] NOT NULL, [TimeStamp] [datetime] NOT NULL, [DayYield] [decimal](18, 2) NULL, [Error] [nvarchar](50) NULL, CONSTRAINT [PrimaryKey_e149e28f-5754-4889-be01-65fafeebce16] PRIMARY KEY CLUSTERED ( [InverterID] ASC, [TimeStamp] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) )
What I now want as SELECT result is to GROUP the table by [TimeStamp] and [InverterID] and get this values as result:
[InverterID]
[TimeStamp]
MIN([TimeStamp])
MAX([TimeStamp])
COUNT(DISTINCT [Error])
[DayYield] from the row with MIN([TimeStamp]) <--- this is my problem
My select Looks like this until now:
SELECT [InverterID], [TimeStamp], MIN([TimeStamp]) AS [FirstTimeStamp], MAX([TimeStamp]) AS [LastTimeStamp], COUNT(DISTINCT [Error]) AS [ErrorCount],<????> AS [FirstDayYield] FROM [InverterData] GROUP BY [TimeStamp], [InverterID];But I don't have a clue how to SELECT the [DayYield] over the MIN of a differnet column. :(
I hope my examples are clear, if you need more information, please ask.
Thanks for your help!
Steffen