数据库结构和查询

Database Structure and Querying

试图弄清楚如何更改我目前拥有的结构,即:

tblHaulLogs

intLogID
intHaulType
intSerial
intOriginSource
intOrigin
intDestinationSource
intDestination
dtmHaulDate
ccyLogPay
intHauler
txtLogNotes
intInvoiceID

在这个 table 中,我正在做的是使用起点和终点源字段来确定起点和终点的 fk 来自哪个 table。这让我感觉很不对。

tblHaulTypes

intHaulTypeID
chrHaulType
intOriginSourceType
intDestinationSourceType

运输类型中的数据Table:

LOT, 1, 1
DEL, 1, 2
RPO, 2, 1

现在让我解释一下: 第一种类型发生在物料从一个销售批次转到另一个销售批次时。 第二种类型发生在商品从销售批次到客户(销售交付)时。 第三种类型发生在商品 returns 从客户返回到销售批次时。

那么项目可以是resold/returned/resold/returned(先租后买系统)。 现在,这是我遇到的问题:

  1. 搬运原木的起点永远是最后一次搬运的终点。因此我认为 origin 字段是多余的。然而,正是最后一次搬家的目的地和新搬家的目的地之间的关系决定了托运人获得的报酬以及运输的类型。

换句话说,即使第一种和第三种在技术上具有相同的字段,但由于前一种移动类型,移动类型并不相同。我需要在这里做什么?我是否完全不知道结构应该是什么?

  1. 根据这个数据我需要回答的问题是: 我的销售批次中有多少商品是新库存(从未售出)。 我有多少商品已售出并退回(与多少次无关)。

我在猜测各个字段和 tables 之间的关系。

您的 tblHaulTypes table 看起来不错。

intHaulTypeID
chrHaulType
intOriginSourceType
intDestinationSourceType

您缺少用于说明从供应商到您批次的交货的运输类型。

必须有一些 table 列出您的拍品。我称之为 tblHaulLot.

intLotNumber
txtLotName
...

我会做一个 tblHaulTransaction table 看起来像这样。

intTransactionID
intHaulTypeID
intHauler
intOriginOrganizationID
intDestinationOrganizationID
intOriginLot      (null if origin is supplier)
intDestinationLot (null if destination is customer)
dtmHaulDate
txtLogNotes

现在,我们需要一个 tblOrganization

intOrganizationID
txtOrganizationName
txtOrganizationAddress
...

ID 为 0 的组织是您的组织。供应商和客户将填写 table 的其余部分。

我会做一个 tblHaulInvoice table 看起来像这样。

intInvoiceID
intTransactionID
ccyTransactionPay
dtmDateInvoiced
AmountInvoiced

发票金额(和支付金额)必须在某些 table 中说明。我不知道 ccy 代表什么,也不知道小数(货币)字段的 3 个字母代码。

How many Items do I have on my sales lots that are new inventory(have never been sold). How many Items do I have that have been sold and returned(doesn't matter how many times).

您的数据模型中没有任何类型的库存 table。我需要更多地了解您的业务才能创建一个或多个库存 tables。