Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

Group by in nested SQL query

$
0
0

Hi,

 

I have a below requirement.

 

Below table we are having.

 

Actually I want group by on stylecode and vendor but wants print turn_around also in output , but in that case it is aggregating based on all three columns which I dont want.How can I get rid from this behaviour?

 

Stylecodevendorturn_around
1111              AAA  5.00
1111              AAA  4.00
2222              BBB  6.00
2222              BBB  3.00
2222              BBB  4.00

 

Output we need.

 

Stylecodevendorturn_aroundCOUNT(based on style code and vendor)SUM(Add turnaround time based on stylecode and vendor)AVERAGE
1111              AAA  5.00294.5
1111              AAA  4.00294.5
2222              BBB  6.003134.3
2222              BBB  3.003134.3
2222              BBB  4.003134.3

 

What I tried with below query and managed to get below result but what i need as above.

 

select "Stylecode",

        "vendor",

  avg ("SUM"/"COUNT") as "AVERAGE"

from ( select

  "Stylecode",

  "vendor",

sum("turn_around") as "SUM",

  count("turn_around") as "COUNT"

  from "HANA"."HANA_ANA2345"

  group by "Stylecode",

  "vendor") group by "Stylecode","vendor"

 

BR

Sumeet


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>