如何避免 UNION on count(*) 按值排序?
How avoid UNION on count(*) sorting by value?
此查询按 select count(*) 的值对结果进行排序。我不希望这发生。我怎样才能避免这种情况?我想按照它们在查询中的写入顺序显示它们。谢谢你的帮助。
这是一条查询:
(select count(*) as num_tweet from [TvPad2-dev].dbo.TWEET where REQUEST_ID = 7
and CREATION_DATE>'2016-02-14 01:00:00.000'
and CREATION_DATE<'2016-02-14 01:29:59.999'
and text like '%arisa%')
union
(select count(*) as num_tweet from [TvPad2-dev].dbo.TWEET where REQUEST_ID = 7
and CREATION_DATE>'2016-02-14 01:30:00.000'
and CREATION_DATE<'2016-02-14 01:59:59.999'
and text like '%arisa%')
使用 UNION ALL。
(select count(*) as num_tweet from [TvPad2-dev].dbo.TWEET where REQUEST_ID = 7
and CREATION_DATE>'2016-02-14 01:00:00.000'
and CREATION_DATE<'2016-02-14 01:29:59.999'
and text like '%arisa%')
union all
(select count(*) as num_tweet from [TvPad2-dev].dbo.TWEET where REQUEST_ID = 7
and CREATION_DATE>'2016-02-14 01:30:00.000'
and CREATION_DATE<'2016-02-14 01:59:59.999'
and text like '%arisa%')
UNION ALL 可以解决问题。如果您将 UNION 更改为 UNION ALL,您将不会得到排序结果。
此查询按 select count(*) 的值对结果进行排序。我不希望这发生。我怎样才能避免这种情况?我想按照它们在查询中的写入顺序显示它们。谢谢你的帮助。
这是一条查询:
(select count(*) as num_tweet from [TvPad2-dev].dbo.TWEET where REQUEST_ID = 7
and CREATION_DATE>'2016-02-14 01:00:00.000'
and CREATION_DATE<'2016-02-14 01:29:59.999'
and text like '%arisa%')
union
(select count(*) as num_tweet from [TvPad2-dev].dbo.TWEET where REQUEST_ID = 7
and CREATION_DATE>'2016-02-14 01:30:00.000'
and CREATION_DATE<'2016-02-14 01:59:59.999'
and text like '%arisa%')
使用 UNION ALL。
(select count(*) as num_tweet from [TvPad2-dev].dbo.TWEET where REQUEST_ID = 7
and CREATION_DATE>'2016-02-14 01:00:00.000'
and CREATION_DATE<'2016-02-14 01:29:59.999'
and text like '%arisa%')
union all
(select count(*) as num_tweet from [TvPad2-dev].dbo.TWEET where REQUEST_ID = 7
and CREATION_DATE>'2016-02-14 01:30:00.000'
and CREATION_DATE<'2016-02-14 01:59:59.999'
and text like '%arisa%')
UNION ALL 可以解决问题。如果您将 UNION 更改为 UNION ALL,您将不会得到排序结果。