
String sql="select * from XXX where 1=1"
if(条件)sql+=" and 字段=值"
if(条件)sql+=" and 字段=值"对于编程语言来说,sql就是一个字符串,拼接成能执行的sql就行了。
提供一个简单思路:1:找出李四的权限
select qx from a where xm='李四'
2:找出张三的权限
select qx from a where xm='张三'
3:使用子查询找出李四有的权限,张三没有的权限
select qx from a where xm='张三' and qx not in (select qx from a where xm='李四')
4:生成数据
insert into a(xm,qx,tf) select ,'张三',qx,1 from a where xm='张三' and qx not in (select qx from a where xm='李四')
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)