2017-04-10 27 views
0

我需要一個MySQL查詢找到SHOPNAME在特定日子開放,MySQL查詢發現SHOPNAME開在某些日子

我Shop_availability表保存shop_name & openday。

這樣的表格。

shop_name openday 
------------------------ 
    shop-A  Monday 
    shop-A  Tuesday 
    shop-A  Wednesday 
    shop-A  Thursday 
    shop-A  Friday 
    shop-B  Monday 
    shop-B  Tuesday 

我想shop_name這在週一打開,週五

Select * availability WHERE openday IN('Monday','Friday') 

上面的查詢不工作,

請幫助我,謝謝,

+2

在查詢中缺少'FROM'!這將是'選擇*從可用性...' – Saty

回答

2

關閉,但你要聚集:

SELECT a.shop_name 
FROM availability a 
WHERE a.openday IN ('Monday', 'Friday') 
GROUP BY a.shop_name 
HAVING COUNT(*) = 2; 

HAVING子句用於驗證是否有兩場比賽在天(天數你正在尋找)。據推測,你的原始數據中沒有重複。

1

您需要組由商店,然後只採取兩個公開日(count(*) = 2

select shop_name 
from availability 
where openday IN('Monday','Friday') 
group by shop_name 
having count(*) = 2