题解 | #将两个 SELECT 语句结合起来(一)#

将两个 SELECT 语句结合起来(一)

https://www.nowcoder.com/practice/a33d5c0ebf434e00b22e2977a5aa3a90

# union & union all

select 

    t1.prod_id  as prod_id,

    t1.quantity as quantity

from OrderItems t1

where t1.quantity = 100

union

select 

    t2.prod_id  as prod_id,

    t2.quantity as quantity

from OrderItems t2

where t2.prod_id like 'BNBG%'

order by prod_id

/*SQL;*/

/*

使用子查询

select 

    t2.prod_id ,

    t2.quantity

from OrderItems t2

where t2.quantity in (

    select 

        t1.quantity

    from OrderItems t1

    where t1.quantity = 100

    )

    or t2.prod_id like "BNBG%"

order by t2.prod_id

;

*/

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务