I have a table with the fields ORDER and FLAG as below and I want to create the GRP column using analytic functions. Can someone adivse how I can do this in sql please?
| ORDER | FLAG | GRP |
|---|---|---|
| 1 | Y | 1 |
| 2 | N | 1 |
| 3 | N | 1 |
| 4 | Y | 2 |
| 5 | N | 2 |
| 6 | Y | 3 |
| 7 | Y | 4 |
I have a table with the fields ORDER and FLAG as below and I want to create the GRP column using analytic functions. Can someone adivse how I can do this in sql please?
| ORDER | FLAG | GRP |
|---|---|---|
| 1 | Y | 1 |
| 2 | N | 1 |
| 3 | N | 1 |
| 4 | Y | 2 |
| 5 | N | 2 |
| 6 | Y | 3 |
| 7 | Y | 4 |
Copyright © 2021 Jogjafile Inc.
Looks like you need to start new group at each
'Y'. Then do running count/sum of them:Note: never use columns like
order,key,frometc as they are reserved keywords in SQL. That's why I renamedordertoorder_id.