手机账号列表查询.sql 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. select t1.tenterprise_userid as userid,
  2. t1.fphonenumber,
  3. t1.faccountno,
  4. t1.siteid,
  5. t1.tagentsid,
  6. t3.fagentname,
  7. t3.fagentnum,
  8. t3.fagentname,
  9. t1.fusertype,
  10. t1.frole,
  11. t1.fname,
  12. t1.fisadministrator,
  13. t1.fissysadministrator,
  14. t5.fappmodel,
  15. case
  16. when t6.tpayinfoid IS null and ((t1.fusertype = '经销商' and t5.fagentamount > 0) or
  17. (t1.fusertype = '企业' and t5.FENTERPRISEUSERAMOUNT > 0)) then 1
  18. else 0 end as fisneedpay,
  19. case
  20. when t6.tpayinfoid IS null and t1.fusertype = '经销商' then t5.fagentamount
  21. when t6.tpayinfoid IS null and t1.fusertype = '企业' then t5.FENTERPRISEUSERAMOUNT
  22. else 0 end as fpayamount,
  23. t5.fagentoldamount,
  24. t2.floginmode,
  25. t2.tenterpriseid,
  26. t3.ftype as fagenttype
  27. from tenterprise_users t1
  28. inner join tenterprise t2 on t1.siteid = t2.siteid
  29. left join tagents t3 on t1.siteid = t3.siteid and t1.tagentsid = t3.tagentsid
  30. inner join tappmodelauth t5 on t1.siteid = t5.siteid and t5.fisdefault = 1
  31. left join tpayinfo t6 on t1.siteid = t6.siteid and ((t1.fusertype = '经销商' and t1.tagentsid = t6.tagentsid) or
  32. (t1.fusertype = '企业' and t1.tenterprise_userid = t6.tenterprise_userid)) and
  33. t6.fbegdate <= GETDATE() and t6.fenddate >= GETDATE()
  34. where t1.fphonenumber =$fphonenumber$ and t2.floginmode in (1, 3)