【SQL】:子查询

SQL创建子查询,即嵌套在其他查询中的查询,利用子查询进行过滤。
在select语句中,子查询总是从内向外处理。
下面的语句,是查询出身份证号为******的客户持有产品,20190612日的行情信息

select * from tfundday where c_fundcode in (select distinct(c_fundcode)
                                            from tsharedetail 
                                            where c_fundacco in (select c_fundacco 
                                                                 from tcustinfo   
                                                                 where c_identityno=' ******'))
                       and d_date=20190612

使用子查询的另一个方法是创建计算字段
可以使用select count(*)对流水表中的行进行计数,且通过提供一条where子句来过滤某个特定客户,仅对该客户的流水进行计数。

select c_custname,
       c_fundacco,
       (select count(*) 
       from tsharedetail 
       where tsharedetail.c_fundacco=tcustinfo.c_fundacco)  as c_count
from tcustinfo 
where c_identityno='*****';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值