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 :: postgres top 10 
Sql :: commit in sql 
Sql :: bigquery add days to date 
Sql :: get yesterday date ISO in psql 
Sql :: create temp table in sql 
Sql :: T-SQL - Delete Column 
Sql :: insert into select mysql 
Sql :: sql server remove primary key without dropping table 
Sql :: sql select min row 
Sql :: sql find table by name 
Sql :: pagination in sql 
Sql :: combine 2 columns search query mysql 
Sql :: postgresql full text search 
Sql :: find number of entries sql 
Sql :: t_sql contains 
Sql :: mysql count table rows 
Sql :: how to write lowercase in sql 
Sql :: update column value in sql 
Sql :: postgresql if else endif 
Sql :: install mysql 5.7 ubuntu 20.04 
Sql :: query to delete a database in mysql 
Sql :: there is no unique constraint matching given keys for referenced table 
Sql :: sql practice 
Sql :: postgres get number of days between two dates 
Sql :: truncate table in sql 
Sql :: what is a unique key in sql 
Sql :: get all employee of salary if more than in sql 
Sql :: sql join 
Sql :: sql update record 
Sql :: Select with remove white spaces in sql 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =