Rahul Tate
Rahul Tate

Reputation: 15

SQL query : Not getting correct output

I have below table instead of zero in add_days and remove_days I want respected output CAN anyone help me to get the correct SQL statement

I TRIED A LOT

E_ID H_ID   ADD_DAYS  REMOVE_DAYS
1   1   "2" "0"
2   2   "4" "0"
2   2   "0" "1"
3   3   "2" "0"
3   3   "0" "4"
3   4   "0" "4"

ACTUAL

E_ID H_ID   ADD_DAYS  REMOVE_DAYS
1   1   "2" "0"
2   2   "4" "0"
2   2   "0" "1"
3   3   "2" "0"
3   3   "0" "4"
3   4   "0" "4"

EXPECTED

E_ID H_ID   ADD_DAYS  REMOVE_DAYS
1   1   "2" "0"
2   2   "4" "1"
3   3   "2" "4"
3   4   "0" "4"

Upvotes: 0

Views: 48

Answers (1)

Fahmi
Fahmi

Reputation: 37473

You can try below -

select e_id, h_id, max(ADD_DAYS),max(REMOVE_DAYS)
from tablename
group by e_id, h_id

Upvotes: 1

Related Questions