Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql select first and last record of each group

select v.*
from (select v.*,
             row_number() over (partition by vehicleid, tripid order by datetime asc) as seqnum_asc,
             row_number() over (partition by vehicleid, tripid order by datetime desc) as seqnum_desc
      from vehicles v
     ) v
where seqnum_asc = 1 or seqnum_desc = 1;
Comment

sql server select last row of each item in group by column

select ID, Name FROM 
(select ID, Name, max(ID) over (partition by Name) as MAX_ID
from Customer) x where ID= MAX_ID
Comment

sql server select last row of each item in group by column

select ID, Name 
FROM (select ID, Name, -- add other columns here
             ROW_NUMBER() over (partition by Name ORDER BY ID DESC) as MAX_ID
      from Customer) x
WHERE MAX_ID = 1
Comment

sql server select last row of each item in group by column

ALTER PROCEDURE [dbo].[Ramiz_Musterija_RowNum]
@Datum DATE,
@BrojKamiona INT
AS SET NOCOUNT ON
SELECT Ime,MusterijaID,RowNum=ROW_NUMBER() OVER(ORDER BY Ime)FROM Musterije
WHERE Datum=@Datum AND BrojKamiona=@BrojKamiona  GROUP BY Ime,MusterijaID
Comment

sql server select last row of each item in group by column

ALTER PROCEDURE [dbo].[Ramiz_Musterija_FindLast]
@Datum DATE,
@BrojKamiona INT
AS SET NOCOUNT ON
SELECT a.* from Musterije a
JOIN (SELECT Ime, MAX(MusterijaID) AS MAXID FROM Musterije GROUP BY Ime) AS b 
ON a.MusterijaID = b.MAXID AND a.Datum=@Datum AND a.BrojKamiona=@BrojKamiona
Comment

sql server select last row of each item in group by column

var rowNumList = from f in customerFindLastList
                     join r in customerRowNumList
                     on f.MusterijaID equals r.MusterijaID
                     select new { r.RowNum };
Comment

PREVIOUS NEXT
Code Example
Sql :: sql convert datetime to year 
Sql :: mysql kill 
Sql :: SQL ORDER BY DESC (Descending Order) 
Sql :: mysql money value 
Sql :: mysql delete duplicates 
Sql :: mysql json query 
Sql :: postgresql delete limit 
Sql :: sql server insert into table 
Sql :: mysql user 
Sql :: sqlalchemy postgres timestamp with timezone 
Sql :: postgresql remove new line from string 
Sql :: MySQL INSERT IGNORE Statement 
Sql :: delete a temporary table mysql 
Sql :: postgresql get date from datetime 
Sql :: reset auto increment mysql 
Sql :: sql round 2 decimal 
Sql :: rename a column in sql server 
Sql :: python simple connect to mysql 
Sql :: commit in sql 
Sql :: sql insert column 
Sql :: postgresql float 2 decimal places 
Sql :: query to find object dependencies in oracle 
Sql :: sql view talbe columns 
Sql :: datepart sql server 
Sql :: is sql fast 
Sql :: creating table in mysql 
Sql :: all tables and views oracle 
Sql :: mysql create a user 
Sql :: mysql community server 
Sql :: mysql on duplicate key update get value from values 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =