Равное распределение ряда в зависимости от его состояния - PullRequest
0 голосов
/ 29 мая 2018

Я новичок в SQL, и я не знаком с хранимой процедурой, в настоящее время я использую SQL 2014. У меня 3 таблицы;

> tblTransaction
    ID  Owner     Country   Region    Vendor    Description
    1   NULL      Country1  Region1   Vendor2   
    4   NULL      Country1  Region1   NULL  
    7   NULL      Country1  Region1   Vendor2   
    10  NULL      Country1  Region1   NULL  
    13  NULL      Country1  Region2   Vendor3   
    16  NULL      Country1  Region2   Vendor3   Description1
    19  NULL      Country1  Region2   Vendor3   Description1
    2   NULL      Country2  Region1   Vendor1   Description1
    5   NULL      Country2  Region2   Vendor1   
    8   NULL      Country2  Region1   Vendor1   
    11  NULL      Country2  Region1   Vendor2   Description1
    14  NULL      Country2  Region1   NULL  
    17  NULL      Country2  Region1   Vendor2   
    20  NULL      Country3  Region1   NULL  
    3   NULL      Country3  Region2   Vendor3   
    6   NULL      Country3  Region2   Vendor3   Description1
    9   NULL      Country3  Region2   NULL  
    12  NULL      Country3  Region2   NULL  
    15  NULL      Country3  Region1   Vendor1   
    18  NULL      Country3  Region2   Vendor1

> tblSkillMatrix
 Owner   IsTeamLead  Country    Vendor   Region     Description
Person1      N      Country1    Vendor1  Region1    
Person2      Y      Country2    Vendor2  Region2    Description1
Person3      N      Country2    Vendor3  Region2    
Person4      Y      Country1    Vendor4  Region1    Description1
Person5      N      Country1    Vendor4  Region1    

> tblAssignment(Output)
ID  Owner     Country   Region    Vendor    Description
1   Person1   Country1  Region1   Vendor2   
4   Person1   Country1  Region1   NULL  
7   Person5   Country1  Region1   Vendor2   
10  Person5   Country1  Region1   NULL  
13  Person4   Country1  Region2   Vendor3   
16  Person2   Country1  Region2   Vendor3   Description1
19  Person2   Country1  Region2   Vendor3   Description1
2   Person2   Country2  Region1   Vendor1   Description1
5   Person2   Country2  Region2   Vendor1   
8   Person2   Country2  Region1   Vendor1   
11  Person4   Country2  Region1   Vendor2   Description1
14  Person3   Country2  Region1   NULL  
17  Person3   Country2  Region1   Vendor2   
20  Person4   Country3  Region1   NULL  
3   Person3   Country3  Region2   Vendor3   
6   Person4   Country3  Region2   Vendor3   Description1
9   Person4   Country3  Region2   NULL  
12  Person2   Country3  Region2   NULL  
15  Person1   Country3  Region1   Vendor1   
18  Person3   Country3  Region2   Vendor1   

Необходимо обновить tblTransaction на основе условия в tblSkillMatrix и, как только это будет сделано, вставить его в таблицу tblAssignment.

Ниже приведены требования:

  • НазначитьИдентификатор TeamLead (если IsTeamLead = 'Y').Описание =
    'Описание1'
  • Если Страна не существует в tblSkillMatrix и если Поставщик НЕДЕЙСТВИТЕЛЕН, присваивайте идентичные идентификаторы только TeamLeads независимо от его Страны.
  • Назначьте максимум из2 транзакции для TeamLead на страну.

  • Для каждой страны не требуется TeamLead.Для
    Non-TeamLead, если Country не существует в tblSkillMatrix, используйте вместо него Region.Должен быть равномерно распределен.

...