如何在WHERE子句中的mysql查询中获取if else语句?

时间:2016-06-14 06:41:43

标签: mysql

我的mysql查询中有错误。任何人都可以帮助我吗?

{{1}}

4 个答案:

答案 0 :(得分:0)

没有必要使用re.findall,无论如何都要尝试这个;)

import re
p = re.compile(r'^\d.*?\b\d{5}$', re.MULTILINE | re.DOTALL)
test_str = "asf aSD  ikugfr jddc ghddfj gjn dfxg \nsdgal fghfh 16 rgjodrisgj frth fghsdf,\ndfghdf dfhgdh gho h ghdof 67676\n\nszdgfads\n2 adf dojosd hsh fghs, \nzfgdf dhgdzsfb dfgdz,\ndzgdzfvg 47564\n\nasdgasdg asdg\n4334 ersga errr ertgerfd ertera erers qereadf erfesfdc wefadfe, \nsfsdgfg-43647"
print(p.findall(test_str))
# => ['2 adf dojosd hsh fghs, \nzfgdf dhgdzsfb dfgdz,\ndzgdzfvg 47564', '4334 ersga errr ertgerfd ertera erers qereadf erfesfdc wefadfe, \nsfsdgfg-43647']

或者你必须使用它,试试这个;)

if else

答案 1 :(得分:0)

像这样使用(你不需要使用if else条件)

select * from user_errors where user_id = '2'
and ((type = 'custom_type' and second_user_id != '2') 
or (type != 'custom_type' and second_user_id = '2'))

答案 2 :(得分:0)

试试这个

select * from user_errors 
where user_id = '2' 
IF(type = 'custom_type', second_user_id != '2', second_user_id = '2' )

答案 3 :(得分:0)

SELECT * FROM user_errors
WHERE user_id = '2'AND  ( case when type = 'custom_type' then second_user_id != '2' else second_user_id = '2' end)