test sql

0

Please login or register to vote for this query.

(click on this box to dismiss)

Joomla

Q&A for Joomla! administrators, users, developers and designers

declare @table table
(day datetime,
mark int, 
name varchar(10), 
cost int, 
salecategory varchar(10), 
costcategory varchar(10))

insert @table values('2019-01-01',10, 'pete',20, 'b', 'b')
insert @table values('2019-01-02',10, 'don',20, 'b', 'b')
insert @table values('2019-01-02',15, 'pete',20, 'c', 'b')
insert @table values('2019-01-02',10, 'john',56, 'c','b')
insert @table values('2019-01-03',15, 'jerry',10, 'd','e')
insert @table values('2019-01-03',15, 'pete',10, 'd','e')
insert @table values('2019-01-04',10, 'pete',10, 'd','e')




SELECT 
LAG(day,1,0) OVER (
        PARTITION BY name
        ORDER BY day) previous_salary
FROM @table

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results