Skip to Content
author's profile photo Former Member
Former Member

GROUP BY USING VIEWS

Hello Guys, I am a beginner to SAP HANA.

I have a sql query something like this:

Select a.username,b.rask_id, count(*)

from tableA a, tableB b

where tableA.id = tableB.doc_id

group by a.username, b.rask_id;

tableA.id relation with tableB.doc_id is 1:n.

Output of the above query is something like this:

user1 20

user2 1

userxxx 12

userN x

Can someone please help me how to create equivalent view for the above query?.

Thanks,

Muks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Mar 23, 2015 at 06:42 PM

    Hello Muks,

    I think your question is how you can do that with a column view (calculation view/analytic view) and not with a "classic" database view?

    Within a calculaiton view (or analytic view) you can join both tables with a join node. To get the counter information you can

    1) use the "count" aggregation functionality in an aggregation node

    or

    2) define a calculated column in a projection node after the join node which returns always the integer value 1 -> in the aggregation node you can use the "sum" aggregation functionality for that new column to get the count.

    Best regards,

    Florian

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks a lot Florian 😊.

      I tried with 2nd option and it worked. But the 1st option didn't. Can you please elaborate option 1. i.e. use "count" aggregation functionality.

      Basically when I use analytic view and add field "user" to output, I can use "count" aggregation on user but then I don't get the desired output. what i want is something like this:

      userName Count

      user1 10

      user2 2

      user3 5

      What I get is

      userName

      10

      2

      1

      I want userName along with Count.

      Thanks,

      Muks

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.