How to use case here

ManiMuthuPandi

I need to create a SQL query to generate the below output from DB.

enter image description here

I am searching a condition like this

When week_val is 1 then hour_val should come from week_val 2 row. Otherwise hour_val comes from same row.

Jaydip Jadhav

You may need subquery with CASE Statment

SELECT CASE WHEN week_val =1 THEN (SELECT TOP 1 hour_val FROM TABLE NAME WHERE week_val <> 1)
       ELSE  hour_val
       END
FROM  TableName

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related