Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

How to extract the column names from SQL query

jmh8981
6 - Meteoroid

Hi, can someone please guide me on below query.

I have sql query like, select sum(col-1), col-2 from table where col-3 ='Jmh'

Required result like

filed_name

col-1

col-2

col-3

 

OR

filed_name-1   filed_name-2  filed_name-3

col-1                 col-2                   col-3

 

 

7 REPLIES 7
Manoj_k
9 - Comet

Hi you can use sql editor to check or write your query

Screenshot 2023-11-22 155935.png

Screenshot 2023-11-22 160026.png

  

jmh8981
6 - Meteoroid

is there any another way without editor to get the same result.

As it has sum(col-1) and it is giving the sum and not name of column. We want column name in result.

CoG
14 - Magnetar

Can you just alias that column in your query? Something like: sum(col-1) AS col-1

 

Otherwise, in Alteryx, you can use the Dynamic Rename Tool in a variety of capacities to rename your columns. That would depend on what you have and what you desired output is (more precisely).

jmh8981
6 - Meteoroid

can plz guide on, How  separates the columns names from sql query 

example-- select sum(col-1), max (col-2) from table;

 

Field_name

co-1  

co-2

CoG
14 - Magnetar

Can you provide some sample input and current output and expected output? I do not fully understand what you are looking for.

jmh8981
6 - Meteoroid

Than u for ur attention.

It is just a sql select query  and whatever aggregate function applied on a column only those column or columns required to separate and want to arrange in row-wise. Like ,

example-- select sum(col-1), max (col-2) from table;

 

Field_name

co-1  

co-2

CoG
14 - Magnetar

It sounds like you might need the Transpose Tool. A sample input and output would really help (for example):

EXAMPLE Sample Input:

col-3sum(col-1)max(col-2)
A57
B10

 

EXAMPLE Sample Output:

col-3NameValue
Asum(col-1)5
Bsum(col-1)1
Amax(col-2)7
Bmax(col-2)0

 

This will go a long way in providing the specifics needed to assist you with your particular use-case. The example above is perfect for the Transpose Tool.

Labels
Top Solution Authors