나는 다음과 같은 정의와 테이블 FOO이 (ID, 유형)과 내가 함께 (그 쌍에 해당하는 모든 데이터를 얻으려면 이드와 타입 그래서 나는 무엇에 속하는지 안다.) 하나의 쿼리에서이 작업을 수행 할 수 있습니까? (내 특정 SQL 언어는 SQLite이다.)SQL의 쌍 목록에있는 행을 선택하는 방법이 있습니까?</p> <pre><code> id INTEGER, type INTEGER, data VARCHAR(32), PRIMARY KEY(id, type) </code></pre> <p>내가 쌍의 목록 제공하고있다 :
2
A
답변
2
SQLite에서 이것을 수행하는 유일한 방법은 where
절에 or
문장을 사용하는 것이다. 또는, 당신은이 작업을 수행 할 수 있습니다 함양을 위해
select
f1.*
from
foo f1
inner join (
select 'id1' as id, 'type1' as type union all
select 'id2', 'type2' union all
select 'id3', 'type3'
) f2 on
f1.id = f2.id
and f1.type = f2.type
에서, where
절 접근 방식은 다음과 같습니다 당신이 많은 쌍을 경우
select
*
from
foo
where
(id = 'id1' and type = 'type1')
or (id = 'id2' and type = 'type2')
or (id = 'id3' and type = 'type3')
0
은 또한 쌍을 들고 두 번째 테이블을 가질 수있다.
select
foo.*
from
foo
inner join pairs
on foo.id = pairs.id and foo.type = pairs.type
관련 문제
- 1. 목록 <Type>
- 2. Grails가 <input type = "file"
- 3. 해시 맵 사용 시도 <Integer, Integer>
- 4. Map <String, TreeMap <Integer, Integer>>를 인스턴스화하는 방법은 무엇입니까?
- 5. 오른쪽이 아닙니다 <type>?
- 6. 인덱스 값없이 HashMap의 값에 액세스 하시겠습니까? 나는 자바 스크립트 방법으로 값을 반환하고</p> <pre><code>HashMap<Integer, Integer> obMap = new HashMap<Integer, Integer>(); obMap.put(new Integer(1),PartnerID); obMap.put(new Integer(2),numwidgets); return obMap; </code></pre> <p>:
- 7. Java - ArrayList를 사용하여 둘 이상의 데이터 유형을 가질 수 있습니까?</p> <pre><code>ArrayList<Integer,Integer,Integer> triple = new ArrayList<Integer,Integer,Integer>(); </code></pre> <p>난이 오류가 발생하지만이 있다면 난 그냥 궁금 해서요주의 사항 :
- 8. 리스트 처리 <Integer> 스레드로
- 9. Java - ArrayList <Integer> ... 매개 변수 ...?
- 10. Bijective "Integer <-> String"function
- 11. 목록 변환 <String, Object >><String, Integer>
- 12. <button> 대 <input type = "image">
- 13. 목록 개체를 만드는 방법 <Integer> 유형
- 14. 포스트 배열은 내가 텍스트 상자</p> <pre><code><input type="text" name="txt[]" id"txt[]" value="test 1" /> <input type="text" name="txt[]" id"txt[]" value="test 2" /> <input type="text" name="txt[]" id"txt[]" value="test 3" /> </code></pre> <p>의 배열을 JQuery와
- 15. ArrayList의 행을 열로 변경하는 방법 <Integer[]>
- 16. 인터페이스 어댑터 <Type> - 인터페이스 <Subtype>
- 17. 의 ConcurrentModificationException</p> <p>확실하지 .... ArrayList에 <Integer>
- 18. Heredoc <<< 또는 <<?
- 19. github add <<<<<<< HEAD
- 20. <input type = "hidden"기능 문제
- 21. JSTL <c:forEach>은 목록 <Integer>을 지원하지 않습니까?
- 22. 내가 두 테이블 <pre><code>documents: id, folder_id folders: id, title </code></pre> <p></p>이
- 23. 초급 : <input type = "folder">?
- 24. C# .NET을 - IList의 <type>
- 25. from_ <type> of Python
- 26. Visual Studio 2010 (C++)의 'cli :: array <Type> ^'에서 'cli :: array <Type> ^'
- 27. 파이썬 - <type 'instance'>를 <type 'str'>으로 변환 하시겠습니까?
- 28. HTML5에 <input type = "picture"> 및/또는 <input type = "video">가없는 이유는 무엇입니까?
- 29. <input type = 'button'/>과 <input type = 'submit'/>의 차이점
- 30. 은 'cli :: array <Type> ^'을 'cli :: array'로 변환 할 수 없습니다. <Type>^[] '
표준 SQL에는 하나의 데이터 구조 : 행 테이블이 있습니다. 나는 SQLite doesn '쌍'또는 '목록'에 대한 데이터 구조를 가지고 있다고 가정합니다. 표, 행, 열, 스칼라 매개 변수 등으로 요구 사항을 명확히하십시오. 감사합니다. – onedaywhen