 |
ขอถามการ Select ข้อมูลแบบปั๊มข้อมูลเพิ่มใน Oracle Sql ค่ะ |
|
 |
|
|
 |
 |
|
อันนี้เป็นตัวอย่าง การแสดงรายการ ของทุกเดือน ส่วน flag คงต้องคิดเอาเองล่ะครับ อ่านแล้วไม่เข้าใจ
Code (SQL)
select g.plan, tmp.dte as `date`, tmp.tran_id, coalesce( tb.amount, 0) as amount
from (
Select '2013-10-01' as dte, 1 as tran_id'
union Select '2013-11-01' as dte, 2 as tran_id'
union Select '2013-12-01' as dte, 3 as tran_id'
union Select '2014-01-01' as dte, 4 as tran_id'
union Select '2014-02-01' as dte, 5 as tran_id'
union Select '2014-03-01' as dte, 6 as tran_id'
union Select '2014-04-01' as dte, 7 as tran_id'
union Select '2014-05-01' as dte, 8 as tran_id'
union Select '2014-06-01' as dte, 9 as tran_id'
union Select '2014-07-01' as dte, 10 as tran_id'
union Select '2014-08-01' as dte, 11 as tran_id'
union Select '2014-09-01' as dte, 12 as tran_id'
) as tmp
left join (
select plan form table group by plan
) as g
left join table as tb on tb.tran_id=tmp.tran_id and tb.plan=g.plan
ปล. ส่วนวันที่ผมไม่แน่ใจ่ว่า วิธีการเก็บเป็นอย่างไรนะครับ อันนี้แค่เป็นตัวอย่างนะครับ ประยุกต์ใช้ดูเองครับ
|
 |
 |
 |
 |
Date :
2015-02-02 12:50:20 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|