SELECT distinct COUNT(CustomerID) AS Num, Country FROM Customers
where country in (select distinct top 3 country from Customers order by DESC)
GROUP BY Country
是不是在union中也不能用order?
...全文
875打赏收藏
为啥这里边提示order by错误!比较强的大哥们过来看看呗
SELECT distinct COUNT(CustomerID) AS Num, Country FROM Customers where country in (select distinct top 3 country from Customers order by DESC) GROUP BY Country 是不是在union中也不能用order?
--对union中的各语句使用order by
select * from(
select top 3 id from sysobjects order by id)a
union --或者union all
select * from(
select top 3 id from sysobjects order by id desc)a
--对最终结果order by
select top 3 id from syscolumns
union --或者union all
select top 3 id from sysobjects
order by id desc
SELECT distinct COUNT(CustomerID) AS Num, Country FROM Customers
where country in (
select distinct top 3 country from Customers order by country DESC) --排序的列名呢?
GROUP BY Country
SELECT distinct COUNT(CustomerID) AS Num, Country FROM Customers
where country in (select distinct top 3 country from Customers order by country DESC)
GROUP BY Country