I have two tables one with zip codes together with addresses (tableA) and another layer with zip codes and values (tableB), this layer for example has zip code = 1234567 and a value of 50, zip code 2345678 has a value of 22 etc. I need to find a way to randomly select 50 and 22 etc within those zip codes for the addresses to be able to add a new field or use an existing field to update with value of 1, or even better do add the value during the process. When aggregate for the zip codes of addresses (tableA) the sum of the field used should match with the layer of zip codes (tableB) and its values. Result for zip code 1234567 should be 50 randomly picked addresses (of hundreds that exist) added with value of 1 and for zip code 2345678 should have 22 randomly picked addresses with added value of 1. Its a lot of data for each zip code doing this manually, need to find a better way to execute this. Have not find any of the random features in QGIS being able to do this, you can only choose a number or percentage but not based on matching fields etc. Below is an "dummy" example of the two tables used. Address tableA:
zipCode | address | city |
---|---|---|
1234567 | StreetA | CityX |
1234567 | StreetB | CityX |
1234567 | StreetH | CityX |
1234567 | StreetB | CityX |
1234567 | StreetC | CityX |
2345678 | StreetD | CityX |
2345678 | StreetF | CityX |
2345678 | StreetK | CityX |
2345678 | StreetA | CityX |
8901234 | StreetA | CityY |
8901234 | StreetB | CityY |
Zip code tableB:
zipCode | amount |
---|---|
1234567 | 2 |
2345678 | 1 |
8901234 | 0 |
The result I'm looking for is this:
zipCode | address | city | picked |
---|---|---|---|
1234567 | StreetA | CityX | |
1234567 | StreetB | CityX | 1 |
1234567 | StreetH | CityX | |
1234567 | StreetB | CityX | 1 |
1234567 | StreetC | CityX | |
2345678 | StreetD | CityX | |
2345678 | StreetF | CityX | |
2345678 | StreetK | CityX | |
2345678 | StreetA | CityX | 1 |
8901234 | StreetA | CityY | |
8901234 | StreetB | CityY |
Something like... select all addresses (tableA) with zipCode = 1234567 and randomly pick 2 (the value from the amount field "tableB") add a new field and for those picked set value = 1. End result when filter on picked = 1 you should have same amount of addresses for each zip code as the the amount (from zip code "tableB").