I have a payload from which I need to generate SQL Query.
payload={
'Tables':['A', 'B'],
'Cols':{"A":["Product_Name","Product_Desc","Sales"],
"B":['Product_Size', 'Product_Desc']},
'Function': {
'agg': [{'Type': 'sum', 'Value': 'Enrollments'}],
"groupby": ['Product_Name','Product_Desc']
}}
I need to read the above Payload and convert into SQL Query dynamically.
Output:
Query={'A':"SELECT Product_Name, Product_Desc,` SUM(Sales) from A GROUP B Product_Name,Product_Desc;"
,'B': "SELECT Product_Size, Pro FROM B"}
But I am not getting the correct result
if 'groupby' in payload['Function'].keys():
groupby_cols = payload['Function']['groupby']
col_info = payload['Cols']
for i in col_info:
if all(item in col_info[i] for item in groupby_cols):
col_info[i]='GROUP BY ' + ", ".join(groupby_cols)
else:
None
print(col_info)
Output: