I would really appreciate your help with the following problem:
我有一个表(库存——头盔),有3列利息。
catalogue_code purcha stock_
-------------- ------ ------
1001 Box Box
1001 Box Box
1002 EA EA
1002 Set Set
1002 Kit Kit
1004 Set Set
我谨利用以下规则提取资料:
- If a catalogue_code is a duplicate and all its purcha and stock_ attributes have the same value (e.g catalogue_code 1001), select any record.
- If a catalogue_code is a duplicate and some of its purcha and stock_ attributes contain different values (e.g catalogue_code 1002), select the record that has purcha = EA , stock_ = EA .
我在T-SQL中难以执行这一逻辑。
<>Update: 只想指出,原表格没有主要关键。 复制件的去除是为了使目录——编码能够成为主要的关键。
<>Update2: 不幸的是,尼克和埃利亚的答复未能解决问题。 这里是我关于可能实施的假守则:
- Find all the duplicated catalogue_codes
- For each duplicate do:
- Get any pair of stock_ and purcha attributes. Compare the selected pair to all other pairs and store your results in a variable (numberOfIdenticalRecords).
- If numberOfIdenticalRecords = 1 (meaning that all the other records have distinct stock_ and purcha values). In this case, select the record that has purcha = EA and stock_ = EA .
- Else if numberOfIdenticalRecords > 1 (meaning that all the records contain the same stock_ and purcha values), select any record.
执行工作的一个重大缺陷是,它是程序性的,而是标准。 即使有可能执行,但机会却是难以理解和维持。 我一想整个事? 这样做是否有更简单的方法?