mysql if 用法,3个参数,如果第一个为true,则执行第二个参数,否则执行第三个参数
参数:IN shopUserName varchar(50),IN pageNo int,IN pageSize int //请注意varchar(50) 长度
查询体:
BEGIN
SELECT sc.ShopId,sc.ShopState,sc.ExpireTime,sp.Username UserName,activit.ActivityCount ActivityCount
from shopconfigs sc LEFT JOIN managers sp on sc.ShopId = sp.ShopId
LEFT JOIN (SELECT ShopId,count(1) ActivityCount from activities where State<>0 GROUP BY ShopId) activit on activit.ShopId = sc.ShopId
where 1=1 and IF(shopUserName <>'', sp.Username=shopUserName, '1=1')
ORDER BY sc.ShopId ASC
limit pageNo,pageSize ;
END
Like用法
BEGIN
SELECT sc.ShopId,sc.ShopState,sc.ExpireTime,sp.Username UserName,activit.ActivityCount ActivityCount
from shopconfigs sc LEFT JOIN managers sp on sc.ShopId = sp.ShopId
LEFT JOIN (SELECT ShopId,count(1) ActivityCount from activities where State<>0 GROUP BY ShopId) activit on activit.ShopId = sc.ShopId
where 1=1 and IF(shopUserName <>'', sp.Username LIKE CONCAT('%',shopUserName,'%'), '1=1')
ORDER BY sc.ShopId ASC
limit pageNo,pageSize ;
END