sql - How do I exclude entries from a recursive CTE? -


How can I exclude entries from recursive CTT with SQLite?

  Create table member (Group_id VARCHAR, Member_ID VARCHAR); Price ('1', '10 '), (' 1 ', '20'), ('1', '30'), ('1', '-50'), in group group (group_id, member_id) Insert ('2', '30'), ('2', '40 '), (' 3 ',' 1 '), (' 3 ',' 50 '), (' 4 ',' - 10 '), (' 10 ',' 50 '), (' 10 ',' 60 ');  

I want a query that will give me the list of members of the group (recurring). However, a member of the first character, '-' means that the ID after the occurrence is not in the group. For example, '1' members '10', '20 ',' 30 'and '50' '10', however, is a group, so we have to give our children '50 'And' 60 '. However, '50 'is already a member so we can not include' 50 'Finally' 1 'member' 10 ',' 20 ',' 30 ',' -50 'and' 60 '

It seems that this question should work: Select the value ('1') as a member (ID) with

  gm .member_id Member M Inner Join Group Member Village on MG.Group_ID = Join M.Id Left Otter Member and select '-' | | Gm.member_id = e.id WHERE EDID False) Selection ID from Members;  

But I get an error: Several references to the recursive table: Member

How can I do this I want to ?

Note: It does not matter whether the '-50' entry in the result set has been returned.

I do not have a SQLite available for testing, but -50 Even assuming it means that 50 should also be excluded, I think you should look for it:

  with the corresponding member (ID) (Value ('1') Select the union gm.member_id Group Member Join the member gm.group_id = m.id WHERE member_id not like '-%' and do not exist (Select group member 2 g2 Where g2.member_id = '-' || gm.member_id )) Selection ID from members;  

(The above work in postgres)

You usually select from the base table in the recurring section and are included back in the actual CTE. After unwanted lines are filtered with a regular , where the section does not happen by joining CTE. A recurring CTE is defined to end when the JOIN does not get any more rows.

SQLFiddle (Postgres):

expanded after the editing requirements):

As you can see the rows based on your situation Want to exclude (an explanation that you did not give in your original question) The filter can only be out of CTE, again I can not test it with SQLite, only with postgres:

  with the recommended members (ID , Level) AS (VALUES ('4', 1) Select Union gm.member_id, Join Group Member GM members from m level + 1 gm.group_id = m.id) Selection of Member MID, M. Level where ID is not like '-%' and is not present (select from member 1 to 1 where m2.level & lt; m.level and m2.id = '-' || m.id);  

Updated SQLFiddle:


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -