我目前正在尝试输出产品代码和移动,以显示我们销售的产品数量的完整历史记录。
我有两张表private void setLivestockAttribute( String attribute )
{
String value = "";
// 1. Get a List of the Indices of Rows selected.
ObservableList<Integer> selectedIndices = null;
selectedIndices = FXCollections.observableList(tblView_Livestock.getSelectionModel().getSelectedIndices());
// If ONE or MORE rows have been selected.
if ( selectedIndices.size() > 0 )
{
// 2. Get the VALUE of the relevant ATTRIBUTE.
switch (attribute)
{
case LM_Constant.BREED:
value = LM_Utility.getChoice_Breed();
break;
case LM_Constant.SEX:
value = LM_Utility.getChoice_Sex();
break;
case LM_Constant.HAS_CALF:
value = LM_Utility.getChoice_HasCalf();
break;
}
// If there is a VALUE.
if ( value.length() > 0 )
{
ObservableList<LivestockModel> dataList = tblView_Livestock.getItems();
// 3. Update each Livestock record.
DataStore.getInstance().updateLivestock(dataList, selectedIndices, attribute, value);
// 4. Refresh the TableView to show changes.
setLivestockData();
}
}
}
和PUB.movement
我已经做到了这一点
PUB.product
生成的输出是:
SELECT a."prod-code" AS productcode, count(*) AS Movement
FROM (SELECT mov."tran-date", pro."prod-code"
FROM PUB."movement" mov,
PUB."product" pro
WHERE mov.SKU=pro.SKU
AND mov."move-type" = 'i'
AND pro."prod-group" like 'SLA%') a
GROUP BY a."prod-code"
我唯一的问题是,如果当时开具多个发票,它只会将发票计为1,而不是发票数量。 PRODUCTCODE | MOVEMENT
0490786 1
0500012 1
0566003 1
0566004 1
0650594 1
0920127 1
0920154 1
1000557M1 1
1000578M1m 19
中有一个qty
列。我无法将其与当前查询合并以输出正确的库存变动。
答案 0 :(得分:1)
听起来你想要SUM()
字段的qty
而不是动作数量?试试这个:
Select pro."prod-code" As productcode, Sum(mov.qty) As Movement
From PUB.movement As mov
Inner Join PUB.product As pro On mov.SKU = pro.SKU
Where mov."move-type" = 'i'
And pro."prod-group" like 'SLA%'
Group By pro."prod-code";