SQL - print many word between every columns with many conditions

后端 未结 2 1284
眼角桃花
眼角桃花 2021-01-04 11:51

Ok first i have immutable values :

4   8   16   32   64   128   256

and i have one table something like that :

+----+------         


        
2条回答
  •  Happy的楠姐
    2021-01-04 12:47

    The following procedure will return 4 columns. The first and second columns should be displayed. The third column is just the rownum which should be ignored. If the fourth column is not blank then display it in the next row otherwise don't display it.

    DELIMITER //
    create procedure test()
    BEGIN
    declare N int;
    declare X int;
    select count(*) from players where y_of_birth=2000 into N;
    set X = power(2,ceil(log2(N))) -N;
    SELECT full_name, club_name, @row := @row + 1 AS row, 
    case when (@row<= X) 
    then 'any word' else '' end r
    FROM players, (SELECT @row:=0) z
    where y_of_birth=2000;
    END //
    DELIMITER 
    
    call test;
    

提交回复
热议问题