Sql query number of occurrence

可紊 提交于 2019-12-24 07:35:29

问题


I wanna to have query:

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
)

How to write it?


回答1:


This should do it:

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



回答2:


Try something like this:

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


来源:https://stackoverflow.com/questions/2736769/sql-query-number-of-occurrence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!