我在第一个表中使用下面的查询获取行@echo off
setlocal enabledelayedexpansion
for %%a in (*.*) do (
set /a "pre+=1
)
for /f %%a in ('call :star') do (
set /a "count=count+10000"
set /a "fi=10000/pre"
set /a "en=!fi!*!count!"
set "br=!en:~0,-6!"
title !br!
)
pause
:star
echo Some stuff.
echo Some more.
exit /b
,我想知道如何按1,3,4,5,6
排序然后按名称排序最终得到两个数组/行ParentTagId
和{{1 }}
1,3,5
更新
我想知道是否有可能返回多个分组行
我希望上面例子的结果为
(编号为TagId)
1,4,6
表中有var query = 'SELECT * FROM "ArticleTag"
LEFT OUTER JOIN "Tag" ON (
"ArticleTag"."TagId" = "Tag"."TagId"
) WHERE "ArticleId" = $1 ORDER BY "ParentTagId" DESC';
CREATE TABLE IF NOT EXISTS "Tag"(
"TagId" SERIAL NOT NULL,
"ParentTagId" integer,
"Name" varchar,
PRIMARY KEY ("TagId")
);
TagId | ParentTagId | Name |
1 | | a |
2 | | b |
3 | 1 | z |
4 | 1 | f |
5 | 3 | g |
6 | 4 | z |
CREATE TABLE IF NOT EXISTS "ArticleTag"(
"ArticleTagId" SERIAL NOT NULL,
"ArticleId" integer NOT NULL,
"TagId" integer NOT NULL,
FOREIGN KEY ("ArticleId") REFERENCES "Article" ("ArticleId") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY ("TagId") REFERENCES "Tag0" ("TagId") ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY ("ArticleTagId")
);
ArticleTagId | ArticleId | TagId |
0 | 0 | 1 |
1 | 0 | 3 |
2 | 0 | 4 |
3 | 0 | 5 |
4 | 0 | 6 |
,[1,3,4,5,6]
表ArticleTag
Tag
是父子关系,有两个路径,然后返回两个数组{{1} }}
另一个例子
如果ArticleTag表中的1>3>5
在标记表1>4>6
[1,3,5] , [1,4,6]
[1,2,3,4,5,6]
中有三个路径,则返回三个数组1>3>5
答案 0 :(得分:0)
我不确定您的问题,但这会返回Tagid SELECT *
FROM "ArticleTag"
LEFT JOIN "Tag" ON ("ArticleTag"."TagId" = "Tag"."TagId")
ORDER BY "ParentTagId" NULLS FIRST, "Name" ;
<强> SqlFiddle Demo 强>
| ArticleTagId | ArticleId | TagId | TagId | ParentTagId | Name |
|--------------|-----------|-------|-------|-------------|------|
| 0 | 0 | 1 | 1 | (null) | a |
| 2 | 0 | 4 | 4 | 1 | f |
| 1 | 0 | 3 | 3 | 1 | z |
| 3 | 0 | 5 | 5 | 3 | g |
<强>输出强>
View.attributes