c*******o 发帖数: 1722 | 1 have a table tab_a with col_1 and col_2, now i need to map col_1 to
something and insert the results into col_2. for example, if col_1 = 17 then
insert col_2 as "Region 1". how do i do this? thanks a lot. |
B*****g 发帖数: 34098 | 2 case
then
【在 c*******o 的大作中提到】 : have a table tab_a with col_1 and col_2, now i need to map col_1 to : something and insert the results into col_2. for example, if col_1 = 17 then : insert col_2 as "Region 1". how do i do this? thanks a lot.
|
a9 发帖数: 21638 | 3 触发器?
then
【在 c*******o 的大作中提到】 : have a table tab_a with col_1 and col_2, now i need to map col_1 to : something and insert the results into col_2. for example, if col_1 = 17 then : insert col_2 as "Region 1". how do i do this? thanks a lot.
|
c*******o 发帖数: 1722 | 4 can you write a simple example? i know little about mysql. thx
【在 B*****g 的大作中提到】 : case : : then
|
c*******o 发帖数: 1722 | 5 i know how to use the case:
select case col_1
when '17' then 'Region 1'
else row
end as value
from tab_a
and i know insert
insert into tab_a (col_2) values(value)
but how to combine them together?
【在 B*****g 的大作中提到】 : case : : then
|
B*****g 发帖数: 34098 | 6 update ...
set col2 = case when col1 = xx then 'xxxx' else 'xx' end
【在 c*******o 的大作中提到】 : can you write a simple example? i know little about mysql. thx
|
c*******o 发帖数: 1722 | 7 slick, dude. done.
【在 B*****g 的大作中提到】 : update ... : set col2 = case when col1 = xx then 'xxxx' else 'xx' end
|
c*******o 发帖数: 1722 | 8 have a follow up question. what about
set col_2 = case when col_1 = xx, xx, xx then 'xxxx' else 'xx' end;
for multiple to one mapping? just want to save some typing. thx
【在 B*****g 的大作中提到】 : update ... : set col2 = case when col1 = xx then 'xxxx' else 'xx' end
|
B*****g 发帖数: 34098 | 9 col1 in (......)
【在 c*******o 的大作中提到】 : have a follow up question. what about : set col_2 = case when col_1 = xx, xx, xx then 'xxxx' else 'xx' end; : for multiple to one mapping? just want to save some typing. thx
|
c*******o 发帖数: 1722 | 10 dude, you saved my day.
【在 B*****g 的大作中提到】 : col1 in (......)
|
|
|
B*****g 发帖数: 34098 | 11 呵呵,今天不上班,心情好。要不一般我会给你google link,不过那样能提高你的水
平。
【在 c*******o 的大作中提到】 : dude, you saved my day.
|
c*******o 发帖数: 1722 | 12 hoho.. thanks. i will come to this board more often. DB is useful.
DB operations seem so fast, I have been wondering why? if I pull data out
and do some similar operations in outside, the performance will be much
worse than doing so in DB.
【在 B*****g 的大作中提到】 : 呵呵,今天不上班,心情好。要不一般我会给你google link,不过那样能提高你的水 : 平。
|
a9 发帖数: 21638 | 13 编程功夫还不够啊。
的水
【在 c*******o 的大作中提到】 : hoho.. thanks. i will come to this board more often. DB is useful. : DB operations seem so fast, I have been wondering why? if I pull data out : and do some similar operations in outside, the performance will be much : worse than doing so in DB.
|
s****i 发帖数: 36 | 14 Interesting.
It merely depends on what nature ur project is. Here we were advised to move
logic out of SQL as more as possible, as it's a web application and the cos
t of SQL server is much more expensive then that of a web server. We constan
tly encountered sql lock issues due to frequent operation to the database.
【在 c*******o 的大作中提到】 : hoho.. thanks. i will come to this board more often. DB is useful. : DB operations seem so fast, I have been wondering why? if I pull data out : and do some similar operations in outside, the performance will be much : worse than doing so in DB.
|
a9 发帖数: 21638 | 15 你移到逻辑层锁不更严重啦。
move
cos
constan
out
【在 s****i 的大作中提到】 : Interesting. : It merely depends on what nature ur project is. Here we were advised to move : logic out of SQL as more as possible, as it's a web application and the cos : t of SQL server is much more expensive then that of a web server. We constan : tly encountered sql lock issues due to frequent operation to the database.
|
c*******o 发帖数: 1722 | 16 i am totally new in DB. i guess there is always a line.
what amazed me is that DB operationg seems very fast to me.
move
cos
constan
【在 s****i 的大作中提到】 : Interesting. : It merely depends on what nature ur project is. Here we were advised to move : logic out of SQL as more as possible, as it's a web application and the cos : t of SQL server is much more expensive then that of a web server. We constan : tly encountered sql lock issues due to frequent operation to the database.
|