查询返回基于主键的值的计数

时间:2015-07-14 16:29:17

标签: mysql

我目前有两个这种格式的MySql表,其中Student.Type引用了Type.TypeName

    Student:
    CenterID | StudentName | Type
    --------- ------------- ------
    1        | Abc         | A
    1        | Def         | B
    2        | Ebc         | A
    2        | Agc         | A
    2        | Abe         | D
    3        | Gtc         | A
    3        | Hic         | B

    Type:
    TypeName
    --------
    A
    B
    C
    D

我需要的输出是这种形式:

    CenterID | A | B | C | D 
    --------- --- --- --- ---
    1        | 1 | 1 | 0 | 0
    2        | 2 | 0 | 0 | 1
    3        | 1 | 1 | 0 | 0

我发现了类似的问题,但是当“类型”发生变化时,我无法手动将每个案例添加到查询中。

Count of result of a sql query based on values

感谢任何形式的协助。

1 个答案:

答案 0 :(得分:2)

<Button x:Name="VideoTour" Click="VideoTour_Click"  Grid.Column="4" Grid.ColumnSpan="2" Grid.Row="0" BorderBrush="{x:Null}" Style="{StaticResource ButtonStyle1}" VerticalAlignment="Top" Margin="0,14,0,0" Foreground="#FF5ACB2F" Background="{x:Null}">
        <Button.Content>
                <Image Source="../Assets/Movie.png" Width="40" Height="40"/>
        </Button.Content>
</Button> 

 <MediaElement x:Name="PlayTour" Visibility="Collapsed" Grid.Row="1" Grid.RowSpan="2" Grid.Column="1" Grid.ColumnSpan="4"  Source="{Binding URLtour}" AreTransportControlsEnabled="True" Width="260" Height="250"/>