我有一个customers
这样设计的简单表格(我只报告一些字段,关于这个问题的那些):
+ ----------- + --------------- + ---------------- +
+ customer_id + invoice_address + ship_address +
+ ----------- + --------------- + ---------------- +
+ 33 + 234, Walnut Ave + null +
+ ----------- + --------------- + ---------------- +
+ 47 + 66, Smart Ave + null +
+ ----------- + --------------- + ---------------- +
+ 47 + 4, Cool Ave + 45, Dark Street +
+ ----------- + --------------- + ---------------- +
ship_address 为空的行意味着我们也必须使用客户的发票地址进行运输。
第一个问题:这是一个足够好的设计,还是应该所有null
ship_address
字段都填写发票地址(即使相同)而不是留下null
。
第二个问题:保持这样的设计(即使它是糟糕的设计),我如何创建一个 SELECT 查询(如果可能的话),它总是为每一行返回一个地址:ship_address
when NOT null
,否则只是 the invoice_address
,类似于:
SELECT CONCAT_IF_SHIP_ADDRESS_NOT_NULL_OTHERWISE_USE_ONLY_SHIP_ADDRESS(invoice_address, ship_address) AS address FROM customers;
查询 MySQL 数据库。
谢谢,