Let's say we have 6 polygons ( A,B,C,D,E, F)in Spatial database.
A touches B,
B touches C and D,
E and F are not connected to other polygons.
A - B
/ \
C D E F
Having Polygon A, I need to query all polygons connected to it , and do it "recursivelly" Cannot describe it better. So the query by A should return A, B, C, D.
Of course, it is possible to do programmatically, first using SDO_RELATE query B by A, and then query C and D by B. But is it possible to do the task with a single query?
Related
I have some data that looks like this, and identifies pairs that are related:
From_ID To_ID
A C
B C
D E
E D (note this is the same pair as above, in a different order)
E F
A F
G H
Using the logic of 'if x is paired with y, and y is paired with z, then x is paired with z', how can I run an SQL query to return all members of a group?
So for the table above I would like a set of results that identifies or returns two groups: 'A, B, C, D, E, F' and 'G, H', not fussy about how this is done.
It feels like some kind of iterative query but I really have no idea where to start with this so any pointers would be appreciated.
edit: could be run in SQL Developer or HiveQL.
I have a scenario like this:
/-> C -> D \
A -> B - -> G (Contain values of D and F,
\-> E -> F /
Basically at G I have a list of value produce by D and F, let us call D1 and F1.
To create a new value from G, I have to just unwind to B and user can either choose branch C or E and continue to the end G with value of D2 or F2, or he can pop back to A. Let us say the new value is F2, though ABEFG
Now I'm facing a problem, that is I want to edit the values at G, let us say D1.
I want to be able to pop back to D but also allow users pop back to C etc, but D is not in the workflow ABEFG.
My guess is that I have to back up to B and somehow prepare multiple segues up to D but I have no idea if this kind of workflow exists.
Apparently, there is no such way. The solution I found is
Find the instance of B in navigationController!.viewControllers
popToViewController B
Initiate C & D from Main storyboard with identifier (they are already deallocated anyway)
Setup some properties of C & D from D1
pushViewController C & D
Consider the following set of functional dependencies on the relation schema R = (A, B, C, D, E). Decompose the relation into a collection of relation schemas in 4NF. Provide detailed information of the decomposition process.
AB →→ C
B → D
A → E
If you start from the top with AB →→ C, doesn't that fit 4nf and you are done?
I've some variables, Lets say a, b, c, d. All belongs to a fixed interval [0, e]
Now i've some relations between them like
a > b
a > c
b > d
Something like this; I want to make a function which print all the possible cases for this.
Example:
a b c d
a c b d
a b d c
a c b d
In essence, what you have is a directed acyclic graph.
A relatively simple approach is to store, for each variable, a set of the variables that must precede them. (In your example, this storage would map b to {a}, c to {a}, and d to {b}.) You can then write a recursive function that generates all valid tails consisting of a subset of these variables (in your case, for example, the subset {c,d} produces two valid tails: [c,d] and [d,c]). This recursive function examines each variable in the subset and determines whether its prerequisites are already met. (For example, since b maps to {a}, any subset including both a and b cannot produce a tail that begins with b.) If so, then it can recursively call itself on the subset excluding that variable.
There are some optimizations you can then perform, if desired. For example, you can use dynamic programming to avoid repeatedly re-computing the set of valid tails for the same subset.
I'm not sure how to express this problem, so my apologies if it's already been addressed.
I have business rules summarized as a table of outputs given two inputs. For each of five possible value on one axis, and each of five values on another axis, there is a single output. There are ten distinct possibilities in these 25 cells, so it's not the case that each input pair has a unique output.
I have encoded these rules in TSQL with nested CASE statements, but it's hard to debug and modify. In C# I might use an array literal. I'm wondering if there's an academic topic which relates to converting logical rules to matrices and vice versa.
As an example, one could translate this trivial matrix:
A B C
-- -- -- --
X 1 1 0
Y 0 1 0
...into rules like so:
if B OR (A and X) then 1 else 0
...or, in verbose SQL:
CASE WHEN FieldABC = 'B' THEN 1
WHEN FieldABX = 'A' AND FieldXY = 'X' THEN 1
ELSE 0
I'm looking for a good approach for larger matrices, especially one I can use in SQL (MS SQL 2K8, if it matters). Any suggestions? Is there a term for this type of translation, with which I should search?
Sounds like a lookup into a 5x5 grid of data. The inputs on axis and the output in each cell:
Y=1 Y=2 Y=3 Y=4 Y=5
x=1 A A D B A
x=2 B A A B B
x=3 C B B B B
x=4 C C C D D
x=5 C C C C C
You can store this in a table of x,y,outvalue triplets and then just do a look up on that table.
SELECT OUTVALUE FROM BUSINESS_RULES WHERE X = #X and Y = #Y;