Mysql存储过程示例
来源:互联网 发布:奶茶店销售额大数据 编辑:程序博客网 时间:2024/06/07 09:23
MySQL存储过程创建示例
DELIMITER //CREATE PROCEDURE BEGIN declare count int;SELECT count(*) into count FROM goods gd inner join recommend rec on rec.object_id = gd.goods_id where 1=1 and info_state='1' and is_del='1' and is_up='0' and rec.type_code = '33';if count = 0 thenselect tb2.* from (SELECT goods_id,gd.goods_name,goods_no,list_img as img,list_img FROM goods gd where 1=1 and info_state='1' and is_del='1' and is_up='0' and gd.goods_id not in (SELECT goods_id FROM goods gd inner join recommend rec on rec.object_id = gd.goods_id where 1=1 and info_state='1' and is_del='1' and is_up='0' and rec.type_code = '33' )order by gd.in_date desc limit 4) as tb2;elseif count = 1 then select tb1.* from (SELECT goods_id,rec.title as goods_name,goods_no,rec.img,list_img FROM goods gd inner join recommend rec on rec.object_id = gd.goods_id where 1=1 and info_state='1' and is_del='1' and is_up='0' and rec.type_code = '33' order by rec.sort) as tb1 union select tb2.* from (SELECT goods_id,gd.goods_name,goods_no,list_img as img,list_img FROM goods gd where 1=1 and info_state='1' and is_del='1' and is_up='0' and gd.goods_id not in (SELECT goods_id FROM goods gd inner join recommend rec on rec.object_id = gd.goods_id where 1=1 and info_state='1' and is_del='1' and is_up='0' and rec.type_code = '33' )order by gd.in_date desc limit 3) as tb2;elseif count = 2 then select tb1.* from (SELECT goods_id,rec.title as goods_name,goods_no,rec.img,list_img FROM goods gd inner join recommend rec on rec.object_id = gd.goods_id where 1=1 and info_state='1' and is_del='1' and is_up='0' and rec.type_code = '33' order by rec.sort) as tb1 union select tb2.* from (SELECT goods_id,gd.goods_name,goods_no,list_img as img,list_img FROM goods gd where 1=1 and info_state='1' and is_del='1' and is_up='0' and gd.goods_id not in (SELECT goods_id FROM goods gd inner join recommend rec on rec.object_id = gd.goods_id where 1=1 and info_state='1' and is_del='1' and is_up='0' and rec.type_code = '33' )order by gd.in_date desc limit 2) as tb2;elseif count = 3 then select tb1.* from (SELECT goods_id,rec.title as goods_name,goods_no,rec.img,list_img FROM goods gd inner join recommend rec on rec.object_id = gd.goods_id where 1=1 and info_state='1' and is_del='1' and is_up='0' and rec.type_code = '33' order by rec.sort) as tb1 union select tb2.* from (SELECT goods_id,gd.goods_name,goods_no,list_img as img,list_img FROM goods gd where 1=1 and info_state='1' and is_del='1' and is_up='0' and gd.goods_id not in (SELECT goods_id FROM goods gd inner join recommend rec on rec.object_id = gd.goods_id where 1=1 and info_state='1' and is_del='1' and is_up='0' and rec.type_code = '33' )order by gd.in_date desc limit 1) as tb2;else SELECT goods_id,rec.title as goods_name,goods_no,rec.img,list_img FROM goods gd inner join recommend rec on rec.object_id = gd.goods_id where 1=1 and info_state='1' and is_del='1' and is_up='0' and rec.type_code = '33' order by rec.sort;end if;END
创建结束后,进行call存储过程进行调用。
call getNewGoods();
1 1
- MYSQL存储过程示例
- mysql存储过程示例
- MySQL存储过程示例
- mysql存储过程示例
- Mysql 存储过程示例
- mysql存储过程示例
- mysql 存储过程示例
- Mysql存储过程示例
- Mysql - 存储过程示例
- mysql存储过程示例
- MySQL存储过程总结示例
- mysql 存储过程 简单示例
- mysql 存储过程示例1
- MySQL procedure存储过程示例
- Mysql的存储过程示例
- mysql 存储过程 示例代码
- MySql 存储过程使用示例
- mysql 存储过程的示例
- 03、函数
- 解决for循环闭包取值问题
- 模板引擎 Smarty
- js获取高度遇到的问题
- 情感识别概况
- Mysql存储过程示例
- 酒店管理系统_01_Servlet版本-项目搭建(引入Bootstrap)
- opencv学习(5)——腐蚀与膨胀
- MyBatis使用动态SQL语句
- 干货:MySQL 索引原理及慢查询优化
- 文章标题
- 进程的状态
- php中curl的使用
- CODE[VS] 1670 无穷的序列 简单数论