SELECT M.user_name,M.user_id,M.login_name,M.sex,M.phone,N.CashFlowRecCntFROM sys_user MINNER JOIN (SELECT A.user_id,sum(case when B.rec_id is null then 0 else 1 end) as CashFlowRecCntFROM sys_user ALEFT JOIN account_record B on(A.user_id=B.user_id)WHERE substring(A.login_name,1,2)=23 and length(A.login_name)=8GROUP BY A.user_idHAVING sum(case when B.rec_id is null then 0 else 1 end)<=3 ) N on(M.user_id=N.user_id)
自己调试吧!我没有数据库。
SELECT id,name,'cash' AS paytype,cash AS paymoney FROM a WHERE cash > 0
UNION ALL
SELECT id,name,'creditCard' AS paytype,creditCard AS paymoney FROM a WHERE creditCard > 0
UNION ALL
SELECT id,name,'ticket' AS paytype,ticket AS paymoney FROM a WHERE ticket > 0
评论列表(0条)