select b.*, a.billtype from table2 b left join table1 a on b.table_id=a.id
select b.table_id,a.billtype,b.id,b.balance from table1 a,table b where a.id =b.table_id
select * from table_2 LEFT JOIN table_1 on table_1.id=table_2.table_id order by table_id asc
select * from (
select b.table1_id,a.billType,b.jd,b.balance from table1 a
INNER JOIN table2 b on a.id = b.table1_id
where b.jd != 1
)a
UNION ALL
select * from (
select b.table1_id,a.billType,b.jd,sum(b.balance) balance from table1 a
INNER JOIN table2 b on a.id = b.table1_id
where b.jd = 1
GROUP BY b.table1_id,a.billType,b.jd
)b
ORDER BY table1_id,jd;
select b1.table_id,billType,b1.jd,b1.balance distinct
from b b1, b b2, a
where b1.table1_id=b2.table1_id and b1.jd=b2.jd and b1.balance = case when b1.id=b2.id then b1.balance else b1.balance+b2.balance end
order by b1.table_id,b1.jd asc