Example : If you want to show the result like that , If you use master detail table like Loan & loan payment return partially against same lone then you want to show details Loan amount & partially received amount then this is usefull for you.
ID | Flag | Amount |
---|---|---|
1 | A | 200 |
2 | A | 200 |
3 | A | 200 |
4 | B | 100 |
5 | B | 100 |
6 | C | 300 |
7 | C | 300 |
8 | C | 300 |
But I like to display like this:
ID | Flag | amount |
---|---|---|
1 | A | 200 |
2 | 0 | |
3 | 0 | |
4 | B | 100 |
5 | 0 | |
6 | C | 300 |
7 | 300 |
Solution ::
You can use lag
window function,
select t.ID,
case when lag([Flag]) over(order by ID)=[Flag] then '' else [Flag] end [Results]
from t
Search result :: sql server same value show first row only | Duplicate Column value show One Time at top