tsql - How to get the Count of the subgroup in SQL -


How do I get a subgroup calculation? I have Table 1 and Table 2 (below) How do I get table results I am tired, but manage to get only the total rows. I'm trying out in Microsoft SQL

  Table 1 ID Prison Function 1 500 A2 500 B3 500 C4 501 A5 501 B6 502 C7 503 A Table 2 Predi Color 500 Green 501 Red 502 Green 503 Green Result Function Green Red Total A2 1 3b 1 1 2 C 2 0 2   

Whatever I have tried down

  SELECT T1 Join 1, Table 1 T1, from the Task, Calculation (T1PRI) to the left table 2 T2 T1. Predi = T2. Perid Group By T. Function   

And I get this

  Result Function Total A3b2c2    

Try it

  SELECT t1.Function, SUM (case when color = ' Green 'then 1 ELSE 0 END)) Green, in the form of SUM (case when color =' red 'then 1 ELSE 0 END), from the calculation (T1Pride), total 1 table 1 T1 with right Join Table 2 at T2 T1. Predi = T2. Pride Group by T. Function    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -