You need when.otherwise
:
val df = Seq(("ram,shyam,hari",12,10),("shyam,ram,hari",3,5)).toDF("name","id","dt")
df.withColumn("newcol", when($"id" > $"dt", 0).otherwise(1)).show
//+--------------+---+---+------+
//| name| id| dt|newcol|
//+--------------+---+---+------+
//|ram,shyam,hari| 12| 10| 0|
//|shyam,ram,hari| 3| 5| 1|
//+--------------+---+---+------+
Or you can cast the comparison result to int:
df.withColumn("newcol", ($"id" <= $"dt").cast("int")).show
//+--------------+---+---+------+
//| name| id| dt|newcol|
//+--------------+---+---+------+
//|ram,shyam,hari| 12| 10| 0|
//|shyam,ram,hari| 3| 5| 1|
//+--------------+---+---+------+