我对MS SQL查询有疑问。 我有以下想要过滤的数据:
+----+----------+-------+-----------+
| Id | Location | Store | Result |
+----+----------+-------+-----------+
| 1 | AB | 1 | Executed |
| 2 | AB | 1 | Cancelled |
| 3 | AB | 2 | Executed |
| 4 | AB | 2 | Missing |
| 5 | AB | 2 | Executed |
| 6 | CD | 3 | Cancelled |
| 7 | CD | 3 | Executed |
| 8 | EF | 4 | Missing |
| 9 | EF | 4 | Cancelled |
| 10 | GH | 5 | Cancelled |
+----+----------+-------+-----------+
我想达到这个结果:
+----------+-------+----------+
| Location | Store | Result |
+----------+-------+----------+
| AB | 1 | Executed |
| AB | 2 | Executed |
| CD | 3 | Executed |
| EF | 4 | Missing |
| GH | 5 | Cancelled|
+----------+-------+----------+
已应用以下选择标准:
如果结果包含1行,请选择该状态(ID 10)
如果结果具有相同的位置&商店:
每个组中的数据将始终相同,因此对于此示例,如果不符合我想要的条件,则GROUP BY位置,存储就足够了。
提前致谢!
答案 0 :(得分:1)
您可以将MenuController = RouteController.extend({
layoutTemplate: 'menuLayout',
waitOn: function () { return Meteor.subscribe('menu', this.params._id); },
data: function () { return Menu.findOne({_id: this.params._id}) },
});
this.route('/menu/tab1', {
name: 'menu.tab1',
template: 'MenuTab1',
controller: MenuController,
});
this.route('/menu/tab2', {
name: 'menu.tab2',
template: 'MenuTab2',
controller: MenuController,
});
this.route('/menu/tab3', {
name: 'menu.tab3',
template: 'MenuTab3',
controller: MenuController,
});
this.route('/menu/tab4', {
name: 'menu.tab4',
template: 'MenuTab4',
controller: MenuController,
});
与修改后的ROW_NUMBER
:
ORDER BY