SQL query design for getting a table with column depending on a column value in SQL Server -


i sql query in sql server table:

table1:

  id  t value   1   r  2412   1   q 98797   2   r 132   2   q 7589 

i need table:

 id   r_value   q_value  1      2412     98797  2      132      7589 

i used case , when, got

id   r_value   q_value  1      2412     null  1      null     98797 

any appreciated.

use conditional aggregation:

sql fiddle

select     id,     max(case when t = 'r' value end) r_value,     max(case when t = 'q' value end) q_value yourtable group id 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -