Agreed. There is nothing wrong with the above code as well. Logically it should result in the same value.
I am seeing problem when running this as a sql model through dbt.

I tried 10 runs consecutively and it gave me the wrong outputs again and again (not the databricks cell run). On the 11th run the same code results in a different output. Is this kind of a bug or something ?