VbzCart/docs/tables/cust names: Difference between revisions
Jump to navigation
Jump to search
imported>Woozle (added WhenEnt, WhenUpd) |
m (Woozle moved page VbzCart/VbzCart/tables/cust names to VbzCart/docs/tables/cust names without leaving a redirect: part 3/5) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 3: | Line 3: | ||
** '''2009-07-09''' moved to separate wiki page; no design changes | ** '''2009-07-09''' moved to separate wiki page; no design changes | ||
** '''2011-11-23''' added WhenEnt, WhenUpd | ** '''2011-11-23''' added WhenEnt, WhenUpd | ||
* '''Notes''': | |||
** (2011-11-23) Possibly WhenUpd should be removed and replaced with one or both of: | |||
*** WhenCnf (when confirmed) -- stamp whenever a new order is received that contains this email | |||
*** WhenEdt (when edited) -- stamp whenever an admin saves the record | |||
**: same for {{l/vc/table|cust_phones}} and {{l/vc/table|cust_emails}} | |||
==SQL== | ==SQL== | ||
< | <source lang=mysql>CREATE TABLE `cust_names` ( | ||
`ID` INT NOT NULL AUTO_INCREMENT, | `ID` INT NOT NULL AUTO_INCREMENT, | ||
`WhenEnt` DATETIME NOT NULL COMMENT "date when record was first created", | `WhenEnt` DATETIME NOT NULL COMMENT "date when record was first created", | ||
Line 14: | Line 19: | ||
PRIMARY KEY(`ID`) | PRIMARY KEY(`ID`) | ||
) | ) | ||
ENGINE = | ENGINE = InnoDB;</source> | ||
< | ==Utility== | ||
SQL query to get a list of cust records with multiple names: | |||
<source lang=mysql>SELECT | |||
g.*, n.Name | |||
FROM | |||
(SELECT | |||
c.ID, COUNT(n.ID) AS NameCount, GROUP_CONCAT(n.ID) AS NameIDs | |||
FROM | |||
cust_names AS n | |||
LEFT JOIN cust AS c ON n.ID_Cust = c.ID | |||
GROUP BY c.ID | |||
HAVING COUNT(n.ID) > 1) AS g | |||
LEFT JOIN | |||
cust_names AS n ON g.ID = n.ID_Cust | |||
WHERE | |||
n.ID IS NOT NULL | |||
ORDER BY g.ID | |||
</source> |
Latest revision as of 01:56, 25 February 2024
About
- History:
- 2009-07-09 moved to separate wiki page; no design changes
- 2011-11-23 added WhenEnt, WhenUpd
- Notes:
- (2011-11-23) Possibly WhenUpd should be removed and replaced with one or both of:
- WhenCnf (when confirmed) -- stamp whenever a new order is received that contains this email
- WhenEdt (when edited) -- stamp whenever an admin saves the record
- same for Template:L/vc/table and Template:L/vc/table
- (2011-11-23) Possibly WhenUpd should be removed and replaced with one or both of:
SQL
CREATE TABLE `cust_names` (
`ID` INT NOT NULL AUTO_INCREMENT,
`WhenEnt` DATETIME NOT NULL COMMENT "date when record was first created",
`WhenUpd` DATETIME DEFAULT NULL COMMENT "date when record was last updated",
`ID_Cust` INT COMMENT "core_custs.ID",
`Name` VARCHAR(127) COMMENT "customer's name, for shipping label",
`NameSrch` VARCHAR(127) COMMENT "name with delimiters removed, for matching",
`isActive` BOOL DEFAULT FALSE COMMENT "NO=wrong spelling or name; use for searching",
PRIMARY KEY(`ID`)
)
ENGINE = InnoDB;
Utility
SQL query to get a list of cust records with multiple names:
SELECT
g.*, n.Name
FROM
(SELECT
c.ID, COUNT(n.ID) AS NameCount, GROUP_CONCAT(n.ID) AS NameIDs
FROM
cust_names AS n
LEFT JOIN cust AS c ON n.ID_Cust = c.ID
GROUP BY c.ID
HAVING COUNT(n.ID) > 1) AS g
LEFT JOIN
cust_names AS n ON g.ID = n.ID_Cust
WHERE
n.ID IS NOT NULL
ORDER BY g.ID