ผมมีข้อมูลดิบตามตารางนี้ครับ

https://docs.google.com/open?id=0BxtQXMM0lbHJaXhzalRNV2J1V2M

ซึ่งเก็บข้อมูล หมายเลขชื่อคน (HN) จำนวนครั้งที่ทำ (Visit) และคะแนนที่ได้ (Total score) เป็นแต่ละ คอลัม

ผมจะเขียนอัลกอริทึม อย่างไรถึงจะใช้นับได้ว่า การมาพบครั้งต่อมาได้คะแนนดีกว่าครั้งแรก (ครั้งที่ 2 ได้มากกว่า 1 หรือครั้งที่ 3 ได้มากกว่า 2)

ให้แนวทางคร่าวๆ ก็พอครับ

Hiring! บริษัทที่น่าสนใจ

Carmen Software company cover
Carmen Software
Hotel Financial Solutions
Next Innovation (Thailand) Co., Ltd. company cover
Next Innovation (Thailand) Co., Ltd.
We are web design with consulting & engineering services driven the future stronger and flexibility.
KKP Dime company cover
KKP Dime
KKP Dime บริษัทในเครือเกียรตินาคินภัทร
Kiatnakin Phatra Financial Group company cover
Kiatnakin Phatra Financial Group
Financial Service
Fastwork Technologies company cover
Fastwork Technologies
Fastwork.co เว็บไซต์ที่รวบรวม ฟรีแลนซ์ มืออาชีพจากหลากหลายสายงานไว้ในที่เดียวกัน
Thoughtworks Thailand company cover
Thoughtworks Thailand
Thoughtworks เป็นบริษัทที่ปรึกษาด้านเทคโนโยลีระดับโลกที่คว้า Great Place to Work 3 ปีซ้อน
Iron Software company cover
Iron Software
Iron Software is an American company providing a suite of .NET libraries by engineer for engineers.
CLEVERSE company cover
CLEVERSE
Cleverse is a Venture Builder. Our team builds several tech companies.
Nipa Cloud company cover
Nipa Cloud
#1 OpenStack cloud provider in Thailand with our own data center and software platform.
Bangmod Enterprise company cover
Bangmod Enterprise
The leader in Cloud Server and Hosting in Thailand.
CIMB THAI Bank company cover
CIMB THAI Bank
MOVING FORWARD WITH YOU - CIMB is the leading ASEAN Bank
Bangkok Bank company cover
Bangkok Bank
Bangkok Bank is one of Southeast Asia's largest regional banks, a market leader in business banking
MuvMi (Urban Mobility Tech Co.,Ltd.) company cover
MuvMi (Urban Mobility Tech Co.,Ltd.)
Shape the future of urban mobility towards affordable, clean, and safe solutions
T.N. Digital Solution Co., Ltd. company cover
T.N. Digital Solution Co., Ltd.
TNDS has been involving in every first move of banking’s major digital transformation.
KBTG - KASIKORN Business-Technology Group company cover
KBTG - KASIKORN Business-Technology Group
KBTG - "The Technology Company for Digital Business Innovation"
Siam Commercial Bank Public Company Limited company cover
Siam Commercial Bank Public Company Limited
"Let's start a brighter career future together"
Icon Framework co.,Ltd. company cover
Icon Framework co.,Ltd.
Global Standard Platform for Real Estate แพลตฟอร์มสำหรับธุรกิจอสังหาริมทรัพย์ครบวงจร มาตรฐานระดับโลก
REFINITIV company cover
REFINITIV
The Financial and Risk business of Thomson Reuters is now Refinitiv
H LAB company cover
H LAB
Re-engineering healthcare systems through intelligent platforms and system design.
The Gang Technology Co., Ltd. company cover
The Gang Technology Co., Ltd.
We're a Digital Agency that helps our customers transform their business into digital with ease.
LTMH company cover
LTMH
LTMH มุ่งเน้นการพัฒนาผลิตภัณฑ์ที่สามารถช่วยพันธมิตรของเราให้บรรลุเป้าหมาย
Seven Peaks company cover
Seven Peaks
We Drive Digital Transformation
Wisesight (Thailand) Co., Ltd. company cover
Wisesight (Thailand) Co., Ltd.
The Best Choice For Handling Social Media · High Expertise in Social Data · Most Advanced and Secure
MOLOG Tech company cover
MOLOG Tech
We are Modern Logistic Platform, Specialize in WMS, OMS and TMS.
Data Wow Co.,Ltd company cover
Data Wow Co.,Ltd
We enable our clients to realize increased productivity by solving their most complex issues by Data
LINE Company Thailand company cover
LINE Company Thailand
LINE, the world's hottest mobile messaging platform, offers free text and voice messaging + Call
LINE MAN Wongnai company cover
LINE MAN Wongnai
Join our journey to becoming No.1 food platform in Thailand
  • "จำนวนครั้งที่ทำ" อันนี้ผมว่าอธิบายผิดหรือเปล่า ต้องแค่ "ครั้งที่ทำแบบทดสอบ" ก็น่าจะพอ?
  • แม้จะไม่ใช่เรื่องที่ผมจำเป็นต้องรู้ก็ในแนวทางการเขียนโปรแกรมได้ แต่เล่าหน่อยก็ดีครับ ว่าคะแนนเต็มเท่าไหร่ ทำไมคะแนนมันสวิงจังเลย เห็นมีตั้งแต่ศูนย์ถึงสามร้อยกว่าๆ
  • ถ้าคะแนนครั้งแรกดีแล้ว ส่วนครั้งถัดมาเป็น 0 อันนี้ถือว่า user error ไม่นับว่าครั้งนั้นเกิดขึ้นมั้ย?

ไม่ได้ช่วยอะไรเลยแฮะ 55 แต่ดูแล้วก็เรียงคะแนนตามคน-ครั้งที่ทำเรียบร้อย ที่เหลือก็ไม่น่ายากแล้วฮะ

ลองนิยามเหตุการณ์นี้หน่อยครับ ว่าดีขึ้นหรือเปล่า

1 50
2 0
3 30

เพราะครั้งที่ 3 ดีกว่าครั้งที่ 2 แต่จริง ๆ แล้วแย่กว่าครั้งแรก จะให้สรุปว่าดีขึ้นหรือเปล่าครับ

ถ้าสรุปได้แล้ว อัลกอไม่ยากครับ แค่ข้อมูลเรียงตาม HN, Visit ก็สามารถเปรียบเทียบได้แล้ว

var prev_row = {};
for(row in data) {
  if (prev_row.HN != ''
      && prev_row.HN==row.HN
      && prev_row.score < row.score) {
    print row.HN, ': visit#, row.visit, ' is better than visit#', prev_row.visit;
  }
  prev_row.HN = row.HN;
  prev_row.score = row.score;
  prev_row.visit = row.visit;
}
ปัญหาข้อนี้ จัดเป็นปัญหา Classic ครับ ถ้าหากต้องแก้ด้วยคำสั่ง SQL เพียวๆ

วิธีแก้ปัญหานั้น ขึ้นอยู่กับว่าข้อมูลถูกเก็บไว้ที่ไหนและจะใช้อะไรแก้ปัญหาครับ

1) ใช้ Excel:
  
     ก็เพียงใส่สูตรอ้างอิงกับบรรทัดก่อนหน้าเท่านั้น 
    (แต่ต้อง Sort by HN,VisitOrder ก่อน)


2) ใช้ คำสั่ง SQL (เนื่องจากปกติข้อมูลมักอยู่ใน Database อยู่แล้ว)
     
     เนื่องจากคำสั่ง SQL จะประมวลผลเฉพาะภายใน record เดียวกันเท่านั้น ดังนั้น
     เราต้อง Join ให้เกิดการ Shift ดึงข้อมูลมาไว้ record เดียวกันก่อนครับ ดังนี้

     SELECT A.*, B.*, A.totalscore-B.totalscore 
     FROM Stage as A LEFT JOIN Stage as B
     ON A.hn=B.hn AND A.visit=B.visit+1

     เพียงเท่านี้ เราก็จะสามารถคำนวณหาค่าแตกต่างระหว่างครั้งก่อนได้แล้ว 
     โดยเพิ่ม A.totalscore-B.totalscore เข้าไป 
     ต่อจากนั้น เราก็จะสามารถ WHERE หา HN ใดบ้าง ที่ได้ TotalScore เพิ่มขึ้น
     หรือลดลงจากเดิมต่อไปได้ครับ


3) ใช้ Programming Languages
 
     อันนี้ความเห็นข้างบนได้กล่าวไว้แล้วครับ

ขอบคุณครับ ทำได้ซักพักละครับ แต่ "คิดเอาเอง" ว่าโค๊ดตัวเองเขียนมันดู "เห่ยๆ" เลยอยากขอดูแนวทางที่เขียนแล้ว "สั้นลง" บ้าง ขอบคุณอีกทีครับ อิอิ ได้ไอเดียเยอะดี

โจทย์ข้อนี้ ถ้าจะให้ยากขึ้นสำหรับการแก้ด้วย SQL นะครับ ต้องตัดค่า Visit ออกครับ .. โดยบอกว่าข้อมูลดิบเก็บเพียง วันที่, ลูกค้า, คะแนน เท่านั้น .. และให้ทำการเช็คเองว่ามีการเปลี่ยนแปลงคะแนนดีขึ้นจากครั้งก่อนหรือไม่ โดยใช้เพียงวันที่เท่านั้น