小编bal*_*eak的帖子

自定义ORDER BY函数SQL

我对看起来像这样的自定义ORDER BY子句有要求

SQL自定义子句

SELECT * FROM example
ORDER BY 
CASE 
    WHEN name = 'I want this first' THEN 0
    WHEN name = 'I want this second' THEN 1
    WHEN name = 'We get the picture' THEN 2
    ELSE 99   END ASC
Run Code Online (Sandbox Code Playgroud)

但是,此case语句已经增长,我希望能够将排序顺序重用于其他查询。

我看到我的选择是

  1. 复制粘贴!
  2. 专门为此排序顺序添加到表中的另一列

在我看来,似乎我应该能够传递一个函数来执行排序逻辑。但是在SO和google上进行一些搜索后,我什么也找不到,并认为这也可能会帮助其他人。

sql t-sql

2
推荐指数
2
解决办法
795
查看次数

Angular4路由:ResolveStart事件永远不会结束

我有一个使用来自自定义的哈希路由的Angular 4应用程序<base href="/long/required/path/index.html">。这样做是因为需求说明此url必须是项目的根。我正在尝试使用哈希路由来解决此问题。

我看到的问题涉及解析给定路线的数据。给定一个URLlocalhost:8000/long/require/path/index.html#/project/1/document/55

app.routes.ts

export const ROUTES: Routes = [
 {
  path: 'project/:projectId/document/:documentId',
  component: DocumentViewerComponent,
  resolve: { document: DataResolver}
 },
 { path: '**',    component: NoContentComponent }
];
Run Code Online (Sandbox Code Playgroud)

解析器在此处运行并按预期检索数据。

@Injectable()
export class DataResolver implements Resolve<Document> {

constructor(
 private docService: DocumentService,
) { }

public resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Document> {
this.docService.getDocument(route.params.workspaceId,route.params.documentId)
  .subscribe(d => {
    console.log('Document received, waiting for components to load?', d);
    this.docService.documentRecieved(d);
  }
);
 return this.docService.recievedDocument$;
 }
}
Run Code Online (Sandbox Code Playgroud)

documentService

@Injectable()
export class DocumentService {
  private …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

1
推荐指数
1
解决办法
1074
查看次数

标签 统计

angular ×1

angular2-routing ×1

sql ×1

t-sql ×1