3

我有这个数据

DeveloperId   Date             remark
--------------------------------------
1             02/01/2013        Google
1             02/02/2013        MSN
1             02/03/2013        Google
1             02/02/2013        MSN
1             02/01/2013        Yahoo
2             02/01/2013        Google
2             02/02/2013        Yahoo
2             02/03/2013        Google
2             02/01/2013        Google

如何动态查找 google 和 Msn 和 yahoo 的共同日期?

我想把这样的查询放在报告中。

4

5 回答 5

2
-- Query for dates that have all types of remarks
SELECT
  Date
FROM
  data
GROUP BY 
  Date
HAVING COUNT(DISTINCT remark) = (
  SELECT COUNT(DISTINCT remark)
  FROM data
);

或者,如果这不是要求...

-- Query for dates that have more than one remark.
SELECT
  Date
FROM
  data
GROUP BY 
  Date
HAVING COUNT(DISTINCT remark) > 1;

Sql 小提琴

于 2013-02-19T17:55:33.953 回答
1

试试这个:

with temp as
(
    SELECT Date, Remark
    From MyTable
    GROUP BY Date, Remark
)
SELECT Date
FROM temp
GROUP BY Date
Having COUNT(*) > 1

在这里工作小提琴:http ://sqlfiddle.com/#!3/d41d8/9105

于 2013-02-19T17:48:18.463 回答
1

3 种不同言论的共同日期:

SELECT t1.DATE
FROM TABLE T1
INNER JOIN TABLE T2
ON t1.DATE = t2.DATE
AND Remark IN ('google', 'yahoo', 'msn')
GROUP BY t1.DATE, t1.REMARK
HAVING COUNT(t1.DATE) = 3;
于 2013-02-19T17:55:53.883 回答
0
Select Date from data
group by remark, Date  
于 2013-02-19T17:47:27.480 回答
0

尝试:

select "Date"
from myTable
group by "Date"
where remark in ('Google','MSN','Yahoo')
having count(distinct remark) = 3
于 2013-02-19T17:58:17.140 回答