0

如何在 1 行中显示这 3 个结果?我正在使用 Nortwnd 示例数据库:

select top 1 CompanyName from dbo.Customers
select top 1 LastName from employees
select top 1 categoryname from dbo.Categories

我尝试了 Union 和 intersect 但无法得到结果。

所以我想要类似的东西:

CompanyName         | LastName | CategoryName
Alfreds Futterkiste | Buchanan | Beverages
4

2 回答 2

2

我不明白你为什么想要这样的结果,但以下内容会得到你想要的:

SELECT TOP 1 CompanyName,
(
  SELECT TOP 1 LastName FROM dbo.employees
) AS TopLastName,
(
  SELECT TOP 1 categoryname FROM dbo.Categories
) AS TopCategory
FROM dbo.Customers
于 2013-10-29T03:45:00.350 回答
0

试试这个:

select 
CompanyName  = (select top 1 CompanyName from dbo.Customers),
LastName = (select top 1 LastName from employees),
CategoryName = (select top 1 categoryname from dbo.Categories)
于 2013-10-29T03:44:21.900 回答