iT邦幫忙

0

如何下SQL查詢同時開獎號碼

sql

table名為ball,欄位有ba1、ba2、ba3、ba4、ba5、ba6
我想查 球號 22,33,44,這三個號碼的球,同時出現在同一期,該如何下指令呢
目前我只能做有22,33,44任一號出來就顯示的指令,如下:

 SELECT * FROM ball WHERE 
 (ba1 in ('22','33','44') OR 
  ba2 in ('22','33','44') OR 
  ba3 in ('22','33','44') OR 
  ba4 in ('22','33','44') OR 
  ba5 in ('22','33','44') OR
  ba6 in ('22','33','44'))

我有試過把上面OR改成AND
結果也不行
請各位前輩指點一二
謝謝

bravo iT邦新手 5 級 ‧ 2017-07-26 20:28:52 檢舉
try this
SELECT * FROM ball WHERE
(
(ba1 in ('22','33','44')) +
(ba2 in ('22','33','44')) +
(ba3 in ('22','33','44')) +
(ba4 in ('22','33','44')) +
(ba5 in ('22','33','44')) +
(ba6 in ('22','33','44'))
) =3
v121020 iT邦新手 5 級 ‧ 2017-07-26 21:18:24 檢舉
太強了,就是這樣!!!!!
超感謝您的
^^

1 個回答

0
bravo
iT邦新手 5 級 ‧ 2017-07-27 10:06:33
最佳解答
SELECT * FROM ball WHERE 
(
(ba1 in ('22','33','44')) +
(ba2 in ('22','33','44')) + 
(ba3 in ('22','33','44')) + 
(ba4 in ('22','33','44')) + 
(ba5 in ('22','33','44')) +
(ba6 in ('22','33','44'))
) =3

我要發表回答

立即登入回答