Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SQL:
- WITH split(word, str) AS (
- SELECT '', tagword ||','
- UNION ALL SELECT
- substr(str, 0, instr(str, ',')),
- substr(str, instr(str, ',')+1)
- FROM split WHERE str !=''
- ),
- filter_tags as (
- select word from split where word != ''
- )
- select *
- from file
- join match
- on file.id = match.file_id
- join tag
- on match.tag_id = tag.id
- join filter_tags
- on tag.name = filter_tags.word
- group by match.file_id
- having count(1) = (select count(1) from filter_tags)
- order by file.title asc
- -------------------------------------------------------------------------
- Python:
- taglist = tagword.split(",")
- q = session.query(File).join(
- File.contains).filter(
- Tag.name.in_(taglist)).group_by(
- File.title).having(
- func.count()==len(taglist)).all()
Add Comment
Please, Sign In to add comment