F
F
FilimoniC2013-01-31 00:38:52
MySQL
FilimoniC, 2013-01-31 00:38:52

MySQL VIEW: Display ID as text ("decode")

Hi all!
Can you tell me how in MySQL you can map values ​​to other values?
For example, there is a table
event_id, event_type
1, 2
2, 1
3, 3
4, 5
5, 2
...

I want to display as
event_id, event_description
1, buy
2, sell
3, view
4, undefined
5, buy
...

event_type pairs => event_description, of course, are known
. Is it possible to do this with VIEW without using an additional lookup table?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JustLuckyGuy, 2013-01-31
@FilimoniC

select id,
case report.type
when 'P' then amount
when 'N' then -amount
end as amount
from
`report`

S
Sergey, 2013-01-31
@Ualde

VIEW is just SELECT, so who's stopping you from doing

SELECT * FROM t1, t2 WHERE t1.event_id=t2.event_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question