Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the process to realize row-to-column in mysql5

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to achieve row transfer in the process of using mysql5". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to use the process to achieve row transfer in mysql5" bar!

Simply searched the Internet, did not find that mysql has a decode function similar to oracle to achieve row transfer, there are many procedures to achieve dynamic row transfer, try, not suitable for me to use, refer to the help of mysql5, write a process, record memo. Cursors are used, and the examples given in the documentation on the use of cursors are also good, but that's all I can use anyway.

DELIMITER $$

DROP PROCEDURE IF EXISTS `hrb_ yd`.`proc _ hrb_yd_ stat` $$

CREATE DEFINER= `root` @ `192.168.96.1` PROCEDURE `proc_hrb_yd_ stat` (IN $G_id INTEGER (10))

BEGIN

Declare v_name VARCHAR (255)

Declare v INT DEFAULT 0

Declare v1 INT DEFAULT 0

Declare v2 INT DEFAULT 0

Declare v3 INT DEFAULT 0

Declare v4 INT DEFAULT 0

Declare v5 INT DEFAULT 0

Declare v6 INT DEFAULT 0

Declare an int

Declare b varchar (255)

DECLARE done INT DEFAULT 0

Declare cur1 cursor for select id,name from hrb_yd_admin where g_id=$G_id

DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1

Select count (id) into v from hrb_yd_admin where g_id=$G_id

Open cur1

Repeat

Fetch cur1 into a,b

If not done then

Select count (id) into v1 from hrb_yd_visit_table where user_id=an and visit_way=' site visits'; / * number of field visits * /

Select count (id) into v2 from hrb_yd_visit_table where user_id=an and visit_way=' phone'; / *-number of calls * /

Select count (id) into v3 from hrb_yd_visit_table where user_id=an and visit_way='E-mail'; / *-number of emianl visits * /

Select count (id) into v4 from hrb_yd_visit_table where user_id=an and visit_way =''; / *-number of other visits * /

Select count (id) into v5 from hrb_yd_visit_table where user_id=an and visit_un_purpose=' is'; / *-- number of recommended successes * /

Select count (id) into V6 from hrb_yd_visit_table where user_id=an and visit_un_purpose=' No; / *-the number of successes not recommended * /

Select b,v1,v2,v3,v4,v5,v6

End if

Until done end repeat

Close cur1

END$$

DELIMITER

At this point, I believe you have a deeper understanding of "how to use the process to achieve row transfer in mysql5". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report