不会写的sql

如何关联数据字典表中的两个关键字段确定唯一性


select 

         t_dict_data20.id_ dictData20_id_,
       t_dict_data20.name_ dictData20_name_,
       t_dict_data20.code_ dictData20_code_,
       t_dict_data20.index_ dictData20_index_,


t_schedule.id_ schedule_id_,
       t_schedule.competition_ schedule_competition_,
       t_schedule.number_ schedule_number_,
       t_schedule.round_ schedule_round_,
       t_schedule.round_number_ schedule_round_number_,
       t_schedule.site_ schedule_site_,
       t_schedule.match_time_ schedule_match_time_,
       t_schedule.team1_ schedule_team1_,
       t_schedule.team2_ schedule_team2_,
       t_schedule.set_user_ schedule_set_user_,
       t_schedule.set_time_ schedule_set_time_,
       t_schedule.pool_ schedule_pool_,
       t_schedule.team1_code_ schedule_team1_code_,
       t_schedule.team2_code_ schedule_team2_code_,
       t_schedule.match_date_ schedule_match_date_,
       t_schedule.match_day_ schedule_match_day_,
       t_schedule.win_rank_ schedule_win_rank_,
       t_schedule.lose_rank_ schedule_lose_rank_,
       t_schedule.set_type_ schedule_set_type_,
       t_schedule.referee_show_ schedule_referee_show_,
       t_competition.id_ competition_id_,
       t_competition.code_ competition_code_,
       t_competition.name_ competition_name_,
       t_competition.type_ competition_type_,
       t_competition.address_ competition_address_,
       t_competition.detailed_address_ competition_detailed_address_,
       t_competition.start_time_ competition_start_time_,
       t_competition.end_time_ competition_end_time_,
       t_competition.format_ competition_format_,
       t_competition.apply_start_time_ competition_apply_start_time_,
       t_competition.apply_end_time_ competition_apply_end_time_,
       t_competition.sender_ competition_sender_,
       t_competition.send_time_ competition_send_time_,
       t_competition.status_ competition_status_,
       t_competition.gender_ competition_gender_,
       t_competition.rank_pool_fall_ rank_pool_fall_,
       t_competition.pool_pots_ pool_pots_,
       t_competition.knockout_team_ knockout_team_,
       to_char(t_competition.start_time_, 'yyyy') com_year_,
       t_dict_data.ID_ dictData_id_,
       t_dict_data.CODE_ dictData_code_,
       t_dict_data.NAME_ dictData_name_,
       t_dict_data.EN_NAME_ dictData_en_name_,
       t_dict_data.INDEX_ dictData_index_,
       t_competition_team1.id_ competition_team1_id_,
       t_competition_team1.competition_ competition_team1_competition_,
       t_competition_team1.team_ competition_team1_team_,
       t_competition_team1.sign_up_people_ c_t1_sign_up_people_,
       t_competition_team1.sign_up_time_ c_t1_sign_up_time_,
       t_competition_team1.rank_ competition_team1_rank_,
       t_competition_team1.bonus_ competition_team1_bonus_,
       t_competition_team1.integral_ competition_team1_integral_,
       t_competition_team1.then_team_name_ c_t1_then_team_name_,
       t_competition_team1.then_team_unit_ c_t1_then_team_unit_,
       t_competition_team1.simple_name_ c_t1_simple_name_,
       t_competition_team1.then_team_athlete1_ c_t1_then_team_athlete1_,
       t_competition_team1.then_team_athlete2_ c_t1_then_team_athlete2_,
       t_then_unit1.id_ then_unit1_id_,
       t_then_unit1.code_ then_unit1_code_,
       t_then_unit1.name_ then_unit1_name_,
       t_then_athlete1.user_ t_then_athlete1_id_,
       t_then_athlete1.family_name_ || t_then_athlete1.given_name_ t_then_athlete1_name_,
       t_then_athlete2.user_ t_then_athlete2_id_,
       t_then_athlete2.family_name_ || t_then_athlete2.given_name_ t_then_athlete2_name_,
       t_competition_team2.id_ competition_team2_id_,
       t_competition_team2.competition_ competition_team2_competition_,
       t_competition_team2.team_ competition_team2_team_,
       t_competition_team2.sign_up_people_ c_t2_sign_up_people_,
       t_competition_team2.sign_up_time_ c_t2_sign_up_time_,
       t_competition_team2.rank_ competition_team2_rank_,
       t_competition_team2.bonus_ competition_team2_bonus_,
       t_competition_team2.integral_ competition_team2_integral_,
       t_competition_team2.then_team_name_ c_t2_then_team_name_,
       t_competition_team2.then_team_unit_ c_t2_then_team_unit_,
       t_competition_team2.simple_name_ c_t2_simple_name_,
       t_competition_team2.then_team_athlete1_ c_t2_then_team_athlete1_,
       t_competition_team2.then_team_athlete2_ c_t2_then_team_athlete2_,
       t_then_unit2.id_ then_unit2_id_,
       t_then_unit2.code_ then_unit2_code_,
       t_then_unit2.name_ then_unit2_name_,
       t_then_athlete3.user_ t_then_athlete3_id_,
       t_then_athlete3.family_name_ || t_then_athlete3.given_name_ t_then_athlete3_name_,
       t_then_athlete4.user_ t_then_athlete4_id_,
       t_then_athlete4.family_name_ || t_then_athlete4.given_name_ t_then_athlete4_name_,
       t_comp_pool.id_ t_comp_pool_id_,
       t_comp_pool.name_ t_comp_pool_name_,
       t_comp_pool.english_name_,
       t_comp_pool.pool_order_ t_comp_pool_order_,
       t_comp_pool.competition_ t_comp_pool_competition_,
       t_comp_pool.team_count_ t_comp_pool_team_count_,
       t_comp_pool.advance_count_ t_comp_pool_advance_count_,
       t_comp_pool.out_rank_ t_comp_pool_out_rank_,
       t_dict_data10.id_ dictData10_id_,
       t_dict_data10.name_ dictData10_name_,
       t_dict_data10.code_ dictData10_code_,
       t_dict_data10.index_ dictData10_index_,
       
       t_data_status.id_ data_status_id_,
       t_data_status.code_ data_status_code_,
       t_data_status.name_ data_status_name_,
       t_data_status.DATA_STATUS_TYPE_ DATA_STATUS_TYPE_,
       t_data_status.INDEX_ data_status_index_,
       t_data_status.group_ data_status_group_,
       t_data_status.en_name_ data_status_en_name_
  from bv_schedule t_schedule
  left join bv_competition t_competition
    on t_schedule.competition_ = t_competition.id_
  left join sys_dict_data t_dict_data
    on t_schedule.round_ = t_dict_data.id_
  left join bv_competition_team t_competition_team1
    on t_schedule.team1_ = t_competition_team1.id_
  left join bv_unit t_then_unit1
    on t_competition_team1.then_team_unit_ = t_then_unit1.id_
  left join bv_athlete t_then_athlete1
    on t_competition_team1.then_team_athlete1_ = t_then_athlete1.user_
  left join bv_athlete t_then_athlete2
    on t_competition_team1.then_team_athlete2_ = t_then_athlete2.user_
  left join bv_competition_team t_competition_team2
    on t_schedule.team2_ = t_competition_team2.id_
  left join bv_unit t_then_unit2
    on t_competition_team2.then_team_unit_ = t_then_unit2.id_
  left join bv_athlete t_then_athlete3
    on t_competition_team2.then_team_athlete1_ = t_then_athlete3.user_
  left join bv_athlete t_then_athlete4
    on t_competition_team2.then_team_athlete2_ = t_then_athlete4.user_
  left join ath_user t_user
    on t_schedule.set_user_ = t_user.id_
  left join bv_competition_pool t_comp_pool
    on t_schedule.pool_ = t_comp_pool.id_
  left join sys_dict_data t_dict_data10
    on t_schedule.set_type_ = t_dict_data10.id_
  left join sys_dict_data t_dict_data20
    on t_schedule.round_number_ = t_dict_data20.code_
  left join sys_dict_type sa on sa.id_ = t_dict_data20.dict_type_
  left join sys_data_status t_data_status
    on t_schedule.referee_show_ = t_data_status.id_
 WHERE t_schedule.competition_ = '2017062900333162'
 and (sa.id_ =(select id_ from sys_dict_type where code_='matchRound') or t_dict_data20.name_ is null) 
 order by t_schedule.number_ asc, t_dict_data.index_


--select * from bv_schedule a where a.competition_ = '2017062900333162';
--select * from sys_dict_data where code_ ='I'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值