您将如何“规范化”此SQL?

时间:2019-02-22 19:41:48

标签: mysql database-normalization

因此,我将有一个名为“ REPS”的表。在该表中,我将获得此信息。

    <DocFile>
       <FullPathName>P:\StaticFile.pdf</FullPathName>
       <PageRange UseAllPages="true"/>
       <Quantity>1</Quantity>
       <Section>1</Section>
    </DocFile>
    <DocFile>
       <FullPathName>row[0]</FullPathName>
       <PageRange UseAllPages="true"/>
       <Quantity>row[1]</Quantity>
       <Section>1</Section>
    </DocFile>

我需要弄清楚应该如何执行ZIP_CODES部分。应该是邮政编码的JSON格式吗?像这样

`import csv
from lxml import etree as ET

# Assign file locations
csvFile = '/Users/jehringer/python_work/Work Testing/CSV/Order_123.csv'
xmlFile = '/Users/jehringer/python_work/Work Testing/CSV/myXMLFile.xml'


# Build XML Structure
root = ET.Element('UltimateImposition')
redirect = ET.SubElement(root, 'Redirection')
printJob = ET.SubElement(redirect, 'PrintJob')
queue = ET.SubElement(printJob, 'QueueName')
documents = ET.SubElement(printJob, "Documents")
docFile = ET.SubElement(documents, "DocFile")
fullName = ET.SubElement(docFile, "FullPathName")
pageCount = ET.SubElement(docFile, "PageRange")
qty = ET.SubElement(docFile, "Quantity")
section = ET.SubElement(docFile, "Section")

# Define Static Values
ET.SubElement(queue, "Name").text = "process"
ET.SubElement(queue, "FullPathName").text = r"P:\process"

# Open CSV and run through
with open(csvFile, 'r') as csvFiles:
csvData = csv.reader(csvFiles, delimiter=',')
for row in csvData:
    for i in range(2):
        if i == 1:
            fullName.text = "2up_v4_ejectjob.pdf"
            pageCount.set("UseAllPages", "true")
            qty.text = "1"
            section.text = '1'
        else:
            fullName.text = row[0]
            pageCount.set("UseAllPages", "true")
            qty.text = row[1]
            section.text = '1'

# Write to XML
tree = ET.ElementTree(root)
tree.write(xmlFile, pretty_print=True, xml_declaration=True)`

然后,如果我想获取ZIP匹配ZIP_CODES中的任何一个的名称?还是ZIP_CODES应该有它自己的表?

1 个答案:

答案 0 :(得分:1)

我建议您使用一张邮政编码表和一张代表表。然后创建具有自己的ID,代表ID和邮政编码ID的各种映射表。

表格邮政编码

id INT PRIMARY KEY AUTOINCREMENT
name VARCHAR(64)
zipcode VARCHAR(15)  // account for postal codes from Canada etc

表格代表

id INT PRIMARY KEY AUTOINCREMENT
name VARCHAR(64)

表rep_zipcode_map

id INT PRIMARY KEY AUTOINCREMENT
zipcode_id INT
rep_id INT

然后,如果您需要代表提供的邮政编码列表,则可以通过简单的JOIN服务此请求。

另一种方法是使用各种图形数据库。听起来这可能是解决此问题的正确方法。