กระทู้เก่าบอร์ด อ.Yeadram
        
           1,835   8		  
          
					  
		    URL.หัวข้อ / 
		    URL
        
        การคำนวณ ยอดต่อวัน      
    
      อยากขอแนวความคิดเกี่ยวกับวิธีการที่จะทำให้ได้ผลลัพธ์หน้าตาประมาณนี่อะค่ะ
แบบดึงข้อมูล 3 อย่าง เช่น ล้างรถ,ขัดสี,ล้างห้องเครื่อง โดยทั้งสามแบบนี้จะต้อง
1. แยกออกมาอีกว่า ออกใบขายโดยใคร หน้าร้าน หรือว่า พนักงานขาย
2. นับจำนวนรถที่ทำตามรายการข้างบนออกมาแยกของแต่ละวัน
3. รวมจำนวนของแต่ละรายการ
รูปแบบรายงานจะออกมาประมาณนี้ค่ะ
วันที่ ------------- ล้างรถ ----------------------- ขัดสี ------------------- ล้างห้องเครื่อง
------------ หน้าร้าน | พนักงานขาย --- หน้าร้าน | พนักงานขาย --- หน้าร้าน | พนักงานขาย
1/1/2010 ------- 3 | 5 ------------------------ 1 | 7 ------------------------ 1 | 2
2/1/2010 ------- 5 | 3 ------------------------ 0 | 0 ------------------------ 3 | 1
3/1/2010 --------7 | 5 ------------------------ 0 | 2 ------------------------ 3 | 0
4/1/2010 ------- 0 | 7 ------------------------ 2 | 3 ------------------------ 2 | 0
5/1/2010 ------- 6 | 0 ------------------------ 0 | 1 ------------------------ 0 | 1
6/1/2010 ------- 4 | 2 ------------------------ 3 | 0 ------------------------ 1 | 2
รวม ------------ 23 | 22 ----------------------- 6 | 13 --------------------- 10 | 6
    
    
  แบบดึงข้อมูล 3 อย่าง เช่น ล้างรถ,ขัดสี,ล้างห้องเครื่อง โดยทั้งสามแบบนี้จะต้อง
1. แยกออกมาอีกว่า ออกใบขายโดยใคร หน้าร้าน หรือว่า พนักงานขาย
2. นับจำนวนรถที่ทำตามรายการข้างบนออกมาแยกของแต่ละวัน
3. รวมจำนวนของแต่ละรายการ
รูปแบบรายงานจะออกมาประมาณนี้ค่ะ
วันที่ ------------- ล้างรถ ----------------------- ขัดสี ------------------- ล้างห้องเครื่อง
------------ หน้าร้าน | พนักงานขาย --- หน้าร้าน | พนักงานขาย --- หน้าร้าน | พนักงานขาย
1/1/2010 ------- 3 | 5 ------------------------ 1 | 7 ------------------------ 1 | 2
2/1/2010 ------- 5 | 3 ------------------------ 0 | 0 ------------------------ 3 | 1
3/1/2010 --------7 | 5 ------------------------ 0 | 2 ------------------------ 3 | 0
4/1/2010 ------- 0 | 7 ------------------------ 2 | 3 ------------------------ 2 | 0
5/1/2010 ------- 6 | 0 ------------------------ 0 | 1 ------------------------ 0 | 1
6/1/2010 ------- 4 | 2 ------------------------ 3 | 0 ------------------------ 1 | 2
รวม ------------ 23 | 22 ----------------------- 6 | 13 --------------------- 10 | 6
				8 Reply in this Topic. Dispaly 1  pages and you are on page number 1 
				
        
    2 @R06079    
        
  
      ขอบคุณค่ะ จะพยายามทำค่ะ    
    
  
        
    3 @R06097    
        
  
      พอดีติดปัญหาอะค่ะ คือเขียนคิวรี่สำหรับใช้กับรายงานใหม่แล้วพอลองเทสกับ phpmyadmin มันก็รันได้แสดงผลได้นะค่ะ แต่พอสร้างคิวรี่ใน access กลับไม่ได้คะ
อยากทราบว่าเป็นเพราะอะไร คือคำสั่งมันก็เยอะอยู่เหมือนกันค่ะ
    
    
  อยากทราบว่าเป็นเพราะอะไร คือคำสั่งมันก็เยอะอยู่เหมือนกันค่ะ
        
    4 @R06098    
        
  
      1. ใช้กับ Access ไม่ได้ ดูได้จากตรงไหน/รู้ได้อย่างไร หรือว่า มี Error ขึ้นมา error ว่าอย่างไร  เอามาดูครับ
2. การสร้างคิวรี่ก็คือการเขียน SQL Statement ไม่ว่ามันจะยาวจะสั้นแค่ไหน ก็ต้องเอามาดูครับ ไม่งั้นเดาสุ่มบอกสาเหตุไม่ได้เหมือนกันครับ
    
  2. การสร้างคิวรี่ก็คือการเขียน SQL Statement ไม่ว่ามันจะยาวจะสั้นแค่ไหน ก็ต้องเอามาดูครับ ไม่งั้นเดาสุ่มบอกสาเหตุไม่ได้เหมือนกันครับ
        
    5 @R06100    
        
  
      1. สร้างคิวรี่ใน access แล้วพอกดรันมัน error ค่ะ แบบนี้ค่ะ
Syntax error(missing operator) in query expression 'TKD1.InvoiceDate = TKD2.InvoiceDate left outer join (Select a. invoicedate... ประมาณนี้ค่ะ
2. อันนี้ statement ค่ะ
SELECT TKD1.invoicedate ,TKD1.TKD_D as D,TKD2.TKD_S as S,TKD3.TKD_A as AA,TKD4.TKD_B as BB,S61.S6_D ,S62.S6_S,SC1.SC_D,SC2.SC_S , DINI.DN
FROM
(select a.invoicedate,sum(b.quantity) as TKD_D from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="หน้าร้าน" and b.serviceid="2001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) TKD1
left outer join
(select a.invoicedate,sum(b.quantity) as TKD_S from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="พนักงานขาย" and b.serviceid="2001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) TKD2 ON TKD1.InvoiceDate = TKD2.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as TKD_A from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="AA" and b.serviceid="2001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) TKD3
ON TKD2.InvoiceDate = TKD3.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as TKD_B from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="BB" and b.serviceid="2001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) TKD4
ON TKD3.InvoiceDate = TKD4.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as S6_D from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="หน้าร้าน" and b.serviceid="4003" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) S61
ON TKD4.InvoiceDate = S61.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as S6_S from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="พนักงานขาย" and b.serviceid="4003" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) S62
ON S61.InvoiceDate = S62.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as SC_D from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="หน้าร้าน" and b.serviceid="3001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) SC1
ON S61.InvoiceDate = SC1.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as SC_S from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="พนักงานขาย" and b.serviceid="3001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) SC2
ON SC1.InvoiceDate = SC2.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as DN from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.invoicetype="ใบส่งของ" and b.serviceid="1001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) DINI
ON SC2.InvoiceDate = DINI.InvoiceDate
    
    
  Syntax error(missing operator) in query expression 'TKD1.InvoiceDate = TKD2.InvoiceDate left outer join (Select a. invoicedate... ประมาณนี้ค่ะ
2. อันนี้ statement ค่ะ
SELECT TKD1.invoicedate ,TKD1.TKD_D as D,TKD2.TKD_S as S,TKD3.TKD_A as AA,TKD4.TKD_B as BB,S61.S6_D ,S62.S6_S,SC1.SC_D,SC2.SC_S , DINI.DN
FROM
(select a.invoicedate,sum(b.quantity) as TKD_D from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="หน้าร้าน" and b.serviceid="2001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) TKD1
left outer join
(select a.invoicedate,sum(b.quantity) as TKD_S from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="พนักงานขาย" and b.serviceid="2001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) TKD2 ON TKD1.InvoiceDate = TKD2.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as TKD_A from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="AA" and b.serviceid="2001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) TKD3
ON TKD2.InvoiceDate = TKD3.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as TKD_B from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="BB" and b.serviceid="2001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) TKD4
ON TKD3.InvoiceDate = TKD4.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as S6_D from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="หน้าร้าน" and b.serviceid="4003" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) S61
ON TKD4.InvoiceDate = S61.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as S6_S from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="พนักงานขาย" and b.serviceid="4003" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) S62
ON S61.InvoiceDate = S62.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as SC_D from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="หน้าร้าน" and b.serviceid="3001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) SC1
ON S61.InvoiceDate = SC1.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as SC_S from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.flag ="พนักงานขาย" and b.serviceid="3001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) SC2
ON SC1.InvoiceDate = SC2.InvoiceDate
left outer join
(select a.invoicedate,sum(b.quantity) as DN from inv_invoiceheader a inner join inv_invoicedetail b on a.name = b.name
where a.invoicetype="ใบส่งของ" and b.serviceid="1001" and year(a.invoicedate)=2010 and month(a.invoicedate)=5 group by a.invoicedate) DINI
ON SC2.InvoiceDate = DINI.InvoiceDate
        
    6 @R06113    
        
  
      - คุณเอา statement มาทั้งหมดหรือเปล่า ทำไม statement ของคุณไม่จบด้วเครื่องหมาย เซมิโคลอน ( ; )
- phpmyadmin คุณรันผ่าน เว็บบราวเซอร์ใช่หรือไม่ เมื่อคุณรันผ่านแล้ว ต่อมาคิดอยากนำ statement ตัวเดียวกัน มันรันใน Access คุณเขียนขึ้นใหม่เองทั้งหมด หรือว่า ใช้วิธีคัดลอกมาวาง
ถ้าคุณใช้วิธีคัดลอกมาวาง ต้องระวังเรื่องการเข้ารหัส unicode ด้วยนะครับ
ถ้าปัญหาของคุณยังไม่ได้รับการแก้ไข ผมคงต้องหาทางใหม่อีกครั้ง
จะรอความคืบหน้าครับ
    
    
  - phpmyadmin คุณรันผ่าน เว็บบราวเซอร์ใช่หรือไม่ เมื่อคุณรันผ่านแล้ว ต่อมาคิดอยากนำ statement ตัวเดียวกัน มันรันใน Access คุณเขียนขึ้นใหม่เองทั้งหมด หรือว่า ใช้วิธีคัดลอกมาวาง
ถ้าคุณใช้วิธีคัดลอกมาวาง ต้องระวังเรื่องการเข้ารหัส unicode ด้วยนะครับ
ผมเคยใช้วิธีนี้แก้ปัญหา unicode
1 คัดลอกข้อมูลจาก phpmyadmin (จากเว็บบราวเซอร์) เข้าไว้ในคลิปบอร์ด
2 เปิด notepad ทำการวางข้อมูลลงไปทั้งหมด
3 สั่ง Save As ไฟล์นี้ไว้ที่หน้า Desktop โดยที่ เลือกตัวเลือกในช่อง encoding ให้เป็น Unicode
4 ปิดและเปิดไฟล์ Notepad นี้อีกครั้ง
5 คัดลอกข้อมูลจาก Notepad ทั้งหมด เข้าคลิ๊บบอร์ด
6 สร้างคิวรี่อันใหม่ขึ้นมา เปิดในมุมมอง SQL แล้ววางข้อมูลในคลิ๊บบอร์ด ทั้งลงไปให้หมด
7 สำรวจเครื่องหมายให้ถูกต้อง แล้วค่อยรันคิวรี่
ถ้าปัญหาของคุณยังไม่ได้รับการแก้ไข ผมคงต้องหาทางใหม่อีกครั้ง
จะรอความคืบหน้าครับ
        
    7 @R06115    
        
  
      ขอบคุณมากค่ะ ขอไปลองแก้ก่อนนะค่ะ    
    
  
        
    8 @R06119    
        
    
      ทำตามที่คุณ yeadram บอกแล้ว แต่ยังไม่ได้เลยค่ะ 
ตอนนี้เลยเปลี่ยนคำสั่ง ใช้ iff แทนแล้วค่ะ work ค่ะ
    
    
  ตอนนี้เลยเปลี่ยนคำสั่ง ใช้ iff แทนแล้วค่ะ work ค่ะ
      Time: 0.5010s
    
      
		
docNo -- text -- เก็บเลขที่เอกสาร
docDate -- date/time -- เก็บวันที่เอกสาร
docType--- long -- เก็บรหัสประเภทงาน (อิงข้อมูลจากตารางประเภทงาน)
docBy -- long -- เก็บรหัสพนักงาน (อิงข้อมูลจากตารางพนักงาน ถ้ารหัสเป็น 0 ให้ถือว่า "หน้าร้าน")
ให้สร้างคิวรี่ใหม่มาตัวหนึ่ง ทำการเลือกฟิลด์มาแสดง โดย
-1 เลื่อกฟิลด์ DocNo
-2 เลื่อกฟิลด์ DocDate
-3 เชื่อมตาราง "ประเภทงาน" เอาชื่อของงานมาแสดงแทนรหัส
-4 สร้างฟิลด์มาใหม่ เขียนเงื่อนไข "ถ้ารหัสพนักงานเป็น 0 ให้เขียนคำว่า 'หน้าร้าน' ถ้าไม่ใช่ ให้เขียน 'พนักงานขาย'"
ทำการกรุ๊ปข้อมูลต่างๆ ดังนี้
DocNo ให้ใช้ Count
ฟิลด์อื่นๆ ใช้ Group by
ลองเปลี่ยนมุมมองไปเป็น Privot Table
แล้วลองๆ ลุยทำไปครับ (ลากวางๆ ไม่พอใจก็ลบใหม่ ลองผิดลองถูกไปเรื่อยๆ เดี๋ยวก็เจอรูปแบบที่น่าพอใจด้วย?ัวคุณเองครับ)