thinkphp sql语句问题
select*fromuserb,applyawhereb.id=a.uidand((b.check1=$idanda.state1=0)or(b.check2=$ida...
select * from user b,apply a where b.id=a.uid and ((b.check1=$id and a.state1=0) or (b.check2=$id and a.state1=1 and a.state2=0) or (b.check3=$id and a.state1=1 and a.state2=1 and a.state3=0))
转化成thinkphp的sql语句 table或者join都行
例:
$Model->table()->where()->select()
跪求高手解答 展开
转化成thinkphp的sql语句 table或者join都行
例:
$Model->table()->where()->select()
跪求高手解答 展开
1个回答
展开全部
$user=M('user');
$where['_string'] = ' ((check1=$id and state1=0) OR (check2=$id and state1=1 and state2=0) OR (check3=$id and state1=1 and state2=1 and state3=0))';
$list=$user->join('apply ON user.id=apply.uid')->where($where)->select();
试看看,若两表没重复字段应该可以,不行再追问。
$where['_string'] = ' ((check1=$id and state1=0) OR (check2=$id and state1=1 and state2=0) OR (check3=$id and state1=1 and state2=1 and state3=0))';
$list=$user->join('apply ON user.id=apply.uid')->where($where)->select();
试看看,若两表没重复字段应该可以,不行再追问。
更多追问追答
追问
我现在有点变化
select * from user b,apply a where b.id=a.uid and IF(a.dsum <2,b.check1=$id and a.state=0,(b.check1=$id and a.state1=0) or (b.check2=$id and a.state1=1 and a.state2=0) or (b.check3=$id and a.state1=1 and a.state2=1 and a.state3=0))
加了if判断
追答
你这个SQL语句能运行吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询