1

book と temp_table の 2 つのテーブルがあります。book :book_id and tag_idには 2 つの列があり、temp_table ( tag_id) には 1 つの列しかありません。

次のルールを使用して選択を行う必要があります。

  • book に temp_table のすべてのタグが含まれている場合は、結果になります。

たとえば、3冊の本があります。

   First one has tag_id: 1,2,3,4.
   Second - 1,3,4
   Third - 1,2,3,5

temp_table には tag_id: が含まれています1,3,4

必要な選択には、1 冊目と 2 冊目が含まれている必要があります。3D ブックは、temp_table にない tag_id = 5 を持っているため、結果セットに含まれていてはなりません。

4

1 に答える 1

1
select book_id
from book b
inner join temp_table t on t.tag_id = tag_id
group by book_id
having count(distinct tag_id) = (select count(distinct tag_id) from temp_table)
于 2012-11-10T14:05:18.873 に答える