Sql查询发生次数

时间:2010-04-29 11:13:48

标签: sql-server-2005

我想查询:

Select cars.* from cars where cars.code in
(
select carCode from articles where 
numberofrecords with this car (it is not a column) >1
and Accepted=1
order by date
)

怎么写呢?

2 个答案:

答案 0 :(得分:2)

尝试这样的事情:

SELECT  cars.*
FROM    cars
WHERE   cars.code IN (
    SELECT  carCode
    FROM    articles
    WHERE   Accepted = 1
    GROUP BY carCode
    HAVING COUNT(articleId) > 1
)

答案 1 :(得分:2)

这应该这样做:

SELECT c.*
FROM cars c
    JOIN
    (
        SELECT carCode 
        FROM articles
        WHERE Accepted = 1
        GROUP BY carCode
        HAVING COUNT(carCode) > 1
    ) a ON c.code = a.carCode