I have the following table:

Region IdDescription IdUser

Metropolitan Right 5

Metropolitan Left 6

Metropolitan Right 5

Metropolitan Left 6

Country Town Right 5

Country Town Left 6

Country Town Right 5

Country Town Left 6

Metropolitan Right 7

Country Town Left 8

And I want to query the kinds of IdDescription and the relapses of IdDescription (when the same user ask more than once a determined kind of IdDescription in the same region where he asked before) in each region. Like this:

Region IdRight IdLeft SubTotal RIdRigth* RIdLeft** SubTotal GrandTotal

Metropolitan 3 2 5 1 1 2 7

Country Town 2 3 5 1 1 2 7

*IdDescription Right Relapses

**IdDescription Left Relapses

So far, I could think of this...

SELECT region,
       sum(case when idDescription='Right' then 1 else 0 end) as idRight,
       sum(case when idDescription='Left' then 1 else 0 end) as idLeft
FROM tab
GROUP BY region

But that is only the first 3 column you would get... Not have time to tinker further now...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.