嗨,有人可以帮助我关于sql
我在表格中有这些数据:
date_added | location | status 2012-08-01 Manila 1 2012-08-01 Japan 1 2012-08-01 Cebu 1 2012-08-04 Manila 1 2012-08-04 Cebu 1 2012-08-04 Africa 1 2012-08-06 Manila 1 2012-08-06 Japan 1 2012-08-06 Cebu 1
如何在“马尼拉”,“日本”,“宿务”中获取date_added结果并且状态= 1
在我得到日期之前,这三个数据必须存在.
结果应该是:基于此表
date_added 2012-08-01 2012-08-06
因为在2012-08-04’日本’不存在.
我当前的SAMPLE sql:
SELECT date_added FROM TABLE WHERE location ='Manila' AND location ='Japan' AND location ='Cebu' AND STATUS =1;
请帮助…..任何帮助将不胜感激
试试这个:
SELECT DATE_ADDED FROM TABLE WHERE LOCATION IN ('MANILA','JAPAN','CEBU') AND STATUS =1 GROUP BY DATE_ADDED HAVING (COUNT(DISTINCT LOCATION)=3)