0

私はサンプルの日付を入れていますが、私が求めているのと似たようなことをすることになっています. 2 つの列の値が 1 の場合、または 1 つの列のいずれかが 1 の場合、それらの結果だけを返すクエリを実行したいと考えています。ただし、3 つの列すべてを検索し、値が 1 であることがわかった 3 つの列のいずれかで、その結果を返す必要があります。誰でもこれで私を助けてくれませんか。前もって感謝します。

 ID Patient Patient Name    prio  prio2   prio3
 -------------------------------------------------
 1  101563  Robert Riley        1     1       1
 2  101583  Cody Ayers          1     0       1
 3  101825  Jason Lawler        0     0       1
 4  101984  Dustin Lumis        1     0       0
 5  102365  Stacy smith         1     0       0
 6  102564  Frank Milon         1     0       0
 7  102692  Thomas Kroning      1     0       0
 8  102856  Andrew Philips      1     0       0
 9  102915  Alice Davies        0     0       1
 10 103785  Jon Durley          0     0       1
 11 103958  Clayton Folsom      1     1       1
 12 104696  Michelle Holsley    1     1       1
 13 104983  Teresa Jones        1     0       1
 14 105892  Betsy Prat          1     1       0
 15 106859  Casey Ayers         1     1       0
4

3 に答える 3

1

So, basically you want to pull anything where any of the 3 columns prio,prio2, or prio3 =1? Please clarify your question if this isn't what you are asking( for a better answer). Also, you should tag it with what type of SQL.

 SELECT ID,Patient,[Patient Name],prio,prio2, prio3
 FROM uRtable 
 WHERE prio = 1 OR  prio2 = 1 OR prio3 = 1 

But, if you are saying that you want to pull back any row where any of the 3 columns prio,prio2, or prio3 = 1, but at least one of them is 0 (Get any where any of the 3 = 1 but exclude where they all = 1), probably the easiest way to understand that would be

 SELECT ID,Patient,[Patient Name],prio,prio2, prio3
 FROM uRtable 
 WHERE (prio = 1 OR  prio2 = 1 OR prio3 = 1)
 AND (prio = 0 OR  prio2 = 0 OR prio3 = 0)
于 2012-07-09T02:51:13.640 に答える
0

これを試して:

select * from mytable
where prio + prio2 + prio3 = (
    select max(prio + prio2 + prio3)
    from mytable
    where prio = 1 or prio2 = 1 or prio3 = 1
)
于 2012-07-09T03:17:39.037 に答える
-1
SELECT *
FROM tbl
WHERE 1 IN (prio,prio2,prio3)
于 2012-07-09T03:40:16.740 に答える