PARTITION BY Clause
When you specify a column or set of columns with PARTITION BY clause then
it will divide the result set into record partitions and then finally ranking functions
are applied to each record partition separately and the rank will
restart from 1 for each record partition separately.
SQL SERVERselect ROW_NUMBER() OVER(PARTITION BY transactionHead
order by transactionHead) AS Row1,
TransactionHead from TransactionHeadbalance order by code
MYSQL code should look like..
SELECT
@cur:= IF(TransactionHead=@id, @cur+1, 1) AS RowNumber,
@id := TransactionHead FROM TransactionHeadbalance
CROSS JOIN (SELECT @id:=(SELECT MIN(TransactionHead) FROM
TransactionHeadbalance), @cur:=0) AS init
ORDER BY TransactionHeadbalance.TransactionHead
Screen shot:
select ROW_NUMBER() OVER(PARTITION BY transactionHead
order by transactionHead) AS Row1,
TransactionHead from TransactionHeadbalance order by code
MYSQL code should look like..
SELECT
@cur:= IF(TransactionHead=@id, @cur+1, 1) AS RowNumber,
@id := TransactionHead FROM TransactionHeadbalance
CROSS JOIN (SELECT @id:=(SELECT MIN(TransactionHead) FROM
TransactionHeadbalance), @cur:=0) AS init
ORDER BY TransactionHeadbalance.TransactionHead
0 Comments