mysql 使用子查询_mysql子查询用法

本文通过具体案例展示了MySQL中子查询的两种使用方式:作为值和作为表。首先介绍了如何利用子查询作为值来筛选特定ID,接着演示了复杂的多表连接场景下,子查询作为表来丰富查询结果的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mysql子查询用法

1 可以当值来用

select id from hcyuyin_share where id=(select id from hcyuyin_share limit 200000,1)

2 可以当做表来用

select o.nickName,o.sex,o.province,o.city,from_unixtime(m.time,'%Y-%m-%d %H:%i:%s') as starttime,from_unixtime(z.time,'%Y-%m-%d %H:%i:%s') as endtime,ROUND((z.time-m.time)/60) as haoshifenzhong,from_unixtime(z1.time,'%Y-%m-%d') as choujiangtime from (select openid,time from xintjiashen_zhongjiang2 union select openid,time from xintjiashen_meizhong2) as z left join xintjiashen_my as m on z.openid=m.openid left join xintjiashen_zhongjiang1 as z1 on m.openid=z1.openid left join xintjiashen_oauthinfo as o on m.openid=o.wechatId where z1.prize_id !=8

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值