I am trying to declare variables in my view, which i am finding out is not allowed. I need to be able to set each row a specific number based on an ID field. So if an ID field shows up 3 times it should count each Row as (1, 2, 3) and then when the ID changes it should restart the row# to 1.
What i have tried:
I have tried to add the variables in the view but this is not accepted when creating a view.
select
@Row_Number := case when @AppID = `afpd1`.`AppsID` then @Row_Number + 1
else 1 end as num,
@AppID := `afpd1`.`AppsID`,
`afpd1`.`AppsID` AS `AppID1`,`afpd1`.`Amount`
FROM
(
( `app_fee_pay_data` `afpd1` JOIN `tracking` `tra1` ON ( ( `afpd1`.`AppsID` = `tra1`.`tci_application_id` ) ) )
JOIN `fa_app_data` `fad1` ON ( ( `afpd1`.`AppsID` = `fad1`.`ApplicationID` )) join (select @Row_Number := 0) r
)
WHERE
( `tra1`.`tci_fee_submitted` = 11 and `afpd1`.`TxnTypeId` = 2)
The above code gives me the desired results, but i need a work around so i can save this view and use it.