How to use SELECT Sub-Query in alias for a column?
Here's my script:-
/*Declaring variables:*/
SET period= '3';
SET smryseg=concat('sku',$period,'_smry');
SET spend= concat('sku',$period,'')
/*Printing it:*/
SELECT $period; /* #O/P: 3 */
SELECT $smryseg; /* #O/P: sku3_smry */
SELECT $spend; /* #O/P: sku3_spend */
/*now I want to use this variable in my INNER SELECT query:*/
create table IDENTIFIER ($smryseg) as
SELECT sum(spend) as (SELECT $spend)
FROM my_table;
Here, the last query is giving me an error, I also tried using IDENTIFIER, CONCAT, SUBSRING, $ ,removing parenthesis and much more. I just want the name of column 'sum(spend)' obtained as 'sku3_spend' i.e in dynamic format