mysql查询某字段最大的记录集合

mysql查询某字段最大的记录集合

一、

SELECT
    *
FROM
    item a
WHERE
    recommend = (
        SELECT
            MAX(RECOMMEND)
        FROM
            item b
        WHERE
            a.BILLING_ITEM = b.BILLING_ITEM
            AND BINARY BILLING_ITEM IN (
                '汤圆2',
                '汤圆3',
                '汤圆4'
            )
    )
AND BINARY a.billing_item IN (
    '汤圆2',
    '汤圆3',
    '汤圆4'
)

二、

SELECT
    *
FROM
    item a
WHERE
    NOT EXISTS (
        SELECT
            1
        FROM
            item b
        WHERE
            a.billing_item = b.billing_item
        AND b.recommend > a.recommend
    )
AND BINARY a.billing_item IN (
    '汤圆2',
    '汤圆3',
    '汤圆4'
)

你可能感兴趣的:(mysql,mysql)