我有一张这样的表
OrderID Product Quantity
1 A 800
2 B 700
3 C 300
我需要一个选择查询才能将总数量1800分成多个批次(例如3个),如下所示
BatchNo Product Quantity
1 A 600
2 A 200
2 B 400
3 B 300
3 C 300
有没有办法将其作为选择查询?
我使用SQL 2016
答案 0 :(得分:0)
import { Component, Inject } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'salvamont',
templateUrl: './salvamont.component.html'
})
export class SalvamontComponent {
public Trails: HikingTrail[];
constructor(http: Http, @Inject('BASE_URL') baseUrl: string) {
http.get(baseUrl + 'api/SampleData/HikingTrails')
.subscribe(result => {
this.Trails = result.json();
},
error => console.error(error));
if (this.Trails != undefined) {
console.log("has items");
}
}
}
class HikingTrail {
//some members
}
/ Errors in the OLAP storage engine: A duplicate attribute key has been found
when processing: Table: 'ServiceLocation', Column: 'location_facility',
Value: 'Acute'. The attribute is 'Facility'.
/ {“批处理”300或更多时生成输出记录{1}}。使用c#在单个传递中很容易生成输出数据,而不是在tsql中生成输出数据
SqlContext.Pipe.SendResultsStart()
答案 1 :(得分:0)
ceiling(cast(row_number()(order by (select 1)) as decimal (10, 2)) / 3) as BatchNo
这应该满足您的要求。只需将其添加到您的select
语句中即可。您可以通过将其分成更多批次来更改要划分的数字。