How to create select dynamic fields from a table in mysql?

后端 未结 2 851
忘掉有多难
忘掉有多难 2020-12-12 04:26

I have query join in select statement like this :

select a.item_number, total_quantity, store, factory
from (
    select item_number, sum(quantity) as \"tot         


        
2条回答
  •  自闭症患者
    2020-12-12 04:56

    If you are using stored procedure then your query will become easy to use dynamically. Dynamic column name you can manage by integer number or name of columns.
    store your existing query in the variable and use If condition to concat your dynamic query in variable. at last execute the statement by defined variable.

    you can take reference from below link for execute the dynamic code. mysql dynamic query in stored procedure

提交回复
热议问题