我有2个表,第一个表#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[]) {
const char *srcStr = "<AAA>hello world</AAA> this is a text <AAA>this is another text</AAA>";
const char *firstDelim = "<AAA>";
const char *lastDelim = "</AAA>";
char extStr[128] = "";
int srcStrLen, firstDelimLen, lastDelimLen;
int i, catIdx = 0;
srcStrLen = strlen(srcStr);
firstDelimLen = strlen(firstDelim);
lastDelimLen = strlen(lastDelim);
for (i=0; i<srcStrLen; i++){
if (strncmp(&srcStr[i], firstDelim, firstDelimLen) == 0) {
i += firstDelimLen;
catIdx = i;
}
else if (strncmp(&srcStr[i], lastDelim, lastDelimLen) == 0) {
strncat(extStr, &srcStr[catIdx], i - catIdx);
i += lastDelimLen;
if (i != srcStrLen){
strcat(extStr, " ");
}
}
}
printf("%s\n", extStr);
return 0;
}
数据。第二个表or_f_table
or_table
我想做这样的结果: -
or_f_table
f_id | f_o_id | f_u_id
1 | 19 | 1
2 | 5 | 2
3 | 19 | 2
or_table
o_id | o_name
4 | test1
5 | test2
19 | oops2
20 | oops3
SELECT o.o_name,
IF ((SELECT count(*) FROM or_f_table as f
WHERE f.f_u_id = 1 ),'Yes','No') as follow_status
FROM or_table as o
WHERE o.o_name LIKE '%oop%'
我收到了结果
o_name | follow_status
oops2 | Yes
oops3 | No
为什么它不起作用?我应该如何纠正呢
答案 0 :(得分:1)
对于where条件,总会有一个大于0的值。这就是为什么它不起作用。
尝试此操作以获得指定的结果
SELECT o.o_name,
IF ((SELECT count(*) FROM or_f_table as f
WHERE f.f_o_id = o.o_id ),'Yes','No') as follow_status
FROM or_table as o
WHERE o.o_name LIKE '%oop%'