同一张表的并集后的两个值之和

时间:2018-09-11 08:12:33

标签: mysql sql sum union

这是我的查询

private void TransportValueEvent_Click(object sender, EventArgs e)
{
    if (!string.IsNullOrWhiteSpace(textBox4.Text))
    {
        (sender as TextBox).Text = textBox4.Text;
    }
}

我的输出是: enter image description here

如何将这两个重复的值合并为一个。

2 个答案:

答案 0 :(得分:3)

如果您只需要通过“ location_description”字段获取记录计数,则只能使用不使用联合的分组

SELECT location_description AS Crimes,
       COUNT(*)
FROM test_sample
WHERE day_of_week LIKE "%sunday"
  OR day_of_week LIKE "%saturday"
GROUP BY location_description

答案 1 :(得分:3)

现在无需UNION,只需将WHERE调整为包括两天;

SELECT location_description as Crimes,COUNT(*)
FROM test_sample
where test_sample.day_of_week LIKE"%sunday"
   or test_sample.day_of_week LIKE"%saturday"
GROUP BY test_sample.location_description