Sql 显示空值而不是num值

Sql 显示空值而不是num值,sql,sql-server,Sql,Sql Server,我的问题 with with_user_earns as ( -- get father information (start) select father.id, father.str_name, father.id_father, father.ind_father_side_type, 1 as int_user_level from tb_user father where id = @v_user_id unio

我的问题

with with_user_earns as (
            -- get father information (start)
            select father.id, father.str_name, father.id_father, father.ind_father_side_type, 1 as int_user_level from tb_user father where id = @v_user_id

            union all

            -- get son information (stop condition)
            select son.id, son.str_name, son.id_father, son.ind_father_side_type, WUE.int_user_level + 1 
            from tb_user as son inner join with_user_earns as WUE on son.id_father = WUE.id 
            where son.id_father is not null and WUE.int_user_level < @v_max_level
        )

        select aux.* 
        from (

            -- show result
            select with_user_earns.id id_son, with_user_earns.str_name str_son_name, with_user_earns.id_father, father.str_name str_father_name, with_user_earns.ind_father_side_type, with_user_earns.int_user_level, isnull(sum(o.int_score), 0) as int_score
            from with_user_earns inner join tb_order o on o.id_user = with_user_earns.id
                                 inner join tb_user as father on father.id = with_user_earns.id_father                   
            where o.dt_insert between @v_cycle_begin and @v_cycle_end and o.ind_payment_status = 3
            group by with_user_earns.id, with_user_earns.str_name, with_user_earns.id_father, with_user_earns.ind_father_side_type, with_user_earns.int_user_level, father.str_name

        ) as aux
        order by aux.int_user_level, aux.id_son

不清楚你在问什么。输入数据和预期输出。我的结果只显示用户卖出了任何东西。这是因为我按日期和状态类型(已付)进行筛选。如果没有数据,您的查询和问题就没有任何意义。质疑一些数据。你现在能理解吗?“with_user_earns”表返回所有10个用户,但当我按日期筛选时,我会从当前表中选择
DISTINCT
id\u-son值,并对聚合进行
左连接。
My result:
id_son int_score
1   100
2   11100
3   100
10  300

Expected result:
id_son int_score
1   100
2   11100
3   100
4   0
5   0
6   0
7   0
8   0
9   0
10  300