WITH OrganizationChart (Id, [Name], [Level], ManagerID) AS (
SELECT
Id、[名前]、0 ([レベル])、ManagerID
FROM
[dbo].[Employees] emp
WHERE
ManagerID IS NULL
すべて結合
SELECT
emp.ID、 emp.[名前]、[レベル] + 1、 emp.ManagerID
FROM [dbo].[Employees] emp
inner JOIN OrganizationChart d ON (内部結合組織グラフ)
emp.ManagerID = d.Id
)
SELECT [Id], [Name], [Level], [ManagerID] INTO #ctedemo from OrganizationChartCREATE VOLATILE TABLE ctedemo AS (WITH RECURSIVE OrganizationChart (Id, Name, Level, ManagerID) AS) (VOLATILE TABLE ctedemo AS (再帰的な組織図 (Id, Name, Level, ManagerID) AS を使用して) (
SELECT
ID、名前、0 (レベル)、ManagerID
FROM
TEST.Employees emp
WHERE
ManagerID IS NULL
すべて結合
SELECT
emp.ID、 emp.Name、Level + 1、 emp.ManagerID
FROM TEST.Employees emp
inner JOIN OrganizationChart d ON (内部結合組織グラフ)
emp.ManagerID = d.Id
) SELECT Id, Name, Level, ManagerID from OrganizationChart) WITH DATA NO PRIMARY INDEX (プライマリインデックスのない組織図の ID、名前、レベル、マネージャー ID を選択)
ON COMMIT PRESERVE ROWSを宣言して、replace が記録されていない行を保持します。
OrganizationChart (Id, Name, Level, ManagerID) AS を使用して SESSION.ctedemo(ID, Name, Level, ManagerID) に挿入 (
SELECT
ID、名前、0 (レベル)、ManagerID
FROM
従業員EMP
WHERE
ManagerID IS NULL
すべて結合
SELECT
emp.ID、 emp.Name、Level + 1、 emp.ManagerID
FROM Employees emp, OrganizationChart d (従業員からEMP、組織図d)
場所
emp.ManagerID = d.Id
)
SELECT OrganizationChart の ID、名前、レベル、ManagerIDSELECT * from #ctedemoCtedemo から * を選択SELECT * FROM SESSION.ctedemo| ID | 名前 | ManagerID |
| 1 | ジョン | NULL |
| 2 | ジム | 1 |
| 3 | ジェーン | 1 |
| 4 | トム | 3 |
| 5 | ボブ | 4 |
| 6 | ロブ | 3 |
| 7 | マイク | 1 |
| ID | 名前 | レベル | ManagerID |
| 1 | ジョン | 0 | NULL |
| 2 | ジム | 1 | 1 |
| 3 | ジェーン | 1 | 1 |
| 7 | マイク | 1 | 1 |
| 4 | トム | 2 | 3 |
| 6 | ロブ | 2 | 3 |
| 5 | ボブ | 3 | 4 |
Tableau がデータソースを照会する場合、カスタム SQL は次のようなクエリで渡されます。
[TableauSQL] として ( [ All your Custom SQL here (すべてのカスタム SQL はこちら)] ) から [TOP 1 * (上位 1 *)] を選択します。
SQL Server と Teradata では、サブクエリでの CTE の使用がサポートされていないため、エラーになります。
初期 SQL はサブクエリでは渡されないため、CTE に使用できます。
この機能を今後の製品リリースに組み込むことに賛成する方は、次のアイデアに投票してください。
CTE と SQL Server (v.10.0)
001453743

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.