开发者

find out which column has a particular string and return the column number

I have a database table consisting of strings... I need to search for a particular string in the table row by row and return the column number where that string appears... 开发者_运维技巧I am using mysql database..

my table is of the form

QID Question Choice1 Choice2 Choice3 Choice4

I am given two strings... first string will be found under Question column and second string will be found in Choice1 or Choice2 or Choice3 or Choice4 ... I need to find the column number of the column which has my second string ...

Can someone please tell me what to do ?


This is an ugly response but your question is a bit weird.

SELECT COALESCE(IF(col1='thestring',1,NULL), IF(col2='thestring',2,NULL), IF(col3='thestring',3,NULL) ....) FROM somewhere;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜