mysql内容作为列名

时间:2018-01-31 11:07:33

标签: mysql alias

我有一张包含内容和列的表格,如图片(左侧),但我想在我的网页上显示它,格式如图(右)。

我尝试过各种php和mysql语法组合,但仍然无法显示它们。

SELECT DISTINCT
  'NAMA',
  'TEMPAT LAHIR',
  COUNT(PENDIDIKAN) AS Jumlah
FROM
  table_name
GROUP BY
  'TEMPAT LAHIR'
ORDER BY
  NAMA,
  'TEMPAT LAHIR'

enter image description here

2 个答案:

答案 0 :(得分:1)

尝试以下操作。

protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
    base.OnElementChanged(e);

    if (e.OldElement != null)
    {
        RemovePressEvents();
    }

    if (e.NewElement != null)
    {
        AddPressEvents();
    }
}

private void AddPressEvents()
{
    _longPressGestureRecognizer = new UILongPressGestureRecognizer(HandleLongPress);
    Control.TouchDown += HandleTouchDown;
    Control.TouchUpInside += HandleTouchUpInside;
    AddGestureRecognizer(_longPressGestureRecognizer);
}

private void RemovePressEvents()
{
    Control.TouchDown -= HandleTouchDown;
    Control.TouchUpInside -= HandleTouchUpInside;
    RemoveGestureRecognizer(_longPressGestureRecognizer);
}

private void HandleTouchDown(object sender, EventArgs e)
{
    System.Diagnostics.Debug.WriteLine("TOUCH DOWN");
}

private void HandleTouchUpInside(object sender, EventArgs e)
{
    // Note: will not be called if the Long Press begins. Instead,
    // You can determine the end of the press from when HandleLongPress
    // is called and UILongPressGestureRecognizer.State = 
    // UIGestureRecognizerState.Ended
    System.Diagnostics.Debug.WriteLine("TOUCH UP INSIDE");
}

private void HandleLongPress(UILongPressGestureRecognizer o)
{
    switch (o.State)
    {
        case UIGestureRecognizerState.Began:
            System.Diagnostics.Debug.WriteLine("LONG PRESS BEGAN");
            break;

        case UIGestureRecognizerState.Ended:
            System.Diagnostics.Debug.WriteLine("LONG PRESS ENDED");
            break;
    }
}

答案 1 :(得分:0)

你不需要NAMA&#39;在您的查询中,但您想要“Jumlah”#39;柱。像这样:

SELECT DISTINCT
  `TEMPAT LAHIR`,
  COUNT(`PENDIDIKAN`) AS `JumlahCount`,
  `Jumlah`
FROM
  `table_name`
GROUP BY
  `TEMPAT LAHIR`
ORDER BY
  'TEMPAT LAHIR`

之后需要一些PHP才能正确呈现它。我知道这个答案是不完整的,但你的问题也是如此。发表评论的时间太长了。