 |
สอบถามเรื่องการ query ข้อมูล แบบ union เพื่อนำข้อมูลรับ/จ่ายพัสดุ ไปทำรายงาน stockcard แบบเรียงตามวันที่รับจ่าย |
|
 |
|
|
 |
 |
|

ผมต้องการทำรายงาน stockcard แต่ติดที่ รับ กับจ่าย ถ้าเป็นรับ ช่องจ่ายว่าง ถ้าเป็นจ่ายช่องรับว่าง และยังมีจำนวนคงเหลือซึ่งคำนวนในตาราง พัสดุ
เพิ่มเติม ตาราง พัสดุมีเก็บจำนวนคงเหลือด้วยครับ จากรูปไม่ได้ใส่
Code (SQL)
select kindtypeid,one,two,three,four,price from
(select (tb_receive_detail.kindtypeid) as kindtypeid,(tb_receive.date_re) as one,(tb_vendor.VendorName) as two,(tb_receive.invoice_id) as three,(tb_receive_detail.quantity) as four,(tb_receive_detail.price) as price from tb_receive
inner join tb_receive_detail on tb_receive.re_id = tb_receive_detail.re_id
inner join tb_vendor on tb_receive.VendorCode = tb_vendor.VendorCode
union
select (tb_pay_detail.kindtypeid) as kindtypeid,(tb_pay.pay_date) as one,(tb_department.dep_name) as two,(tb_pay.book_id) as three,(tb_pay_detail.pay_amount) as four,(tb_pay_detail.pay_price/tb_pay_detail.pay_amount) as price from tb_pay
inner join tb_pay_detail on tb_pay.pay_id=tb_pay_detail.pay_id
inner join tb_department on tb_pay.dep_id = tb_department.dep_id) as a where kindtypeid = 6 order by one desc
นี้เป็นโค๊ดที่ผมลองทำเบื้องต้น แต่ติดตรงรับจ่าย และคงเหลือครับ ไม่รู้ว่าต้องออกแบบยังไง
ขอบคุณครับ
Tag : PHP, MySQL, HTML/CSS, JavaScript
|
|
 |
 |
 |
 |
Date :
2013-06-10 12:13:38 |
By :
nook563 |
View :
1423 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ มีึคนช่วยแนะนำครับ แต่ต้องไปต่อยอดก่อน คิดว่าน่าจะทำได้แล้วครับคือ
1. เก็บจำนวนคงเหลือตอนรับหรือจ่ายด้วยเพื่อง่ายต่อการ select และความรวดเร็วในการประมวลผล
2. เพิ่ม null as ตามด้วยชื่อ ในฟิวที่เราต้องการให้ว่าง(กรณีนี้คือ ถ้ารับให้จ่ายว่าง ถ้าจ่ายให้รับว่า)
Code (SQL)
select kindtypeid,one,two,three,four,price from
(select (tb_receive_detail.kindtypeid) as kindtypeid,(tb_receive.date_re) as one,(tb_vendor.VendorName) as two,(tb_receive.invoice_id) as three,(tb_receive_detail.quantity) as four,null as five,(tb_receive_detail.price) as price from tb_receive
inner join tb_receive_detail on tb_receive.re_id = tb_receive_detail.re_id
inner join tb_vendor on tb_receive.VendorCode = tb_vendor.VendorCode
union
select (tb_pay_detail.kindtypeid) as kindtypeid,(tb_pay.pay_date) as one,(tb_department.dep_name) as two,(tb_pay.book_id) as three,null as four,(tb_pay_detail.pay_amount) as five,(tb_pay_detail.pay_price/tb_pay_detail.pay_amount) as price from tb_pay
inner join tb_pay_detail on tb_pay.pay_id=tb_pay_detail.pay_id
inner join tb_department on tb_pay.dep_id = tb_department.dep_id) as a where kindtypeid = 6 order by one desc
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2013-06-10 15:40:25 |
By :
nook563 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|