select ifnull((select 1 from table_name where ip = #{ip} limit 1), 0)
其中ifnull(v1,v2),如果v1为null则返回v2,否则返回v1
select 1 中的1代表常量,效率比 select * 高
limit 1 相当于 limit (0,1),即从第0条开始取1条数据
select * from table_name where name is not null order by id desc
字段名+is not null,即判断该字段不为空
order by id,根据id进行排列
desc,降序排列
原文:https://www.cnblogs.com/antguo/p/12928884.html