คือตอนนี้ผมเขียนโปรแกรมในลักษณะแบบเก็บค่าจากฐานข้อมูลก่อน ค่อยประมวลผลที่ตัวโปรแกรม
แต่ทราบว่างานบางอย่างสามารถประมวลผลที่ฐานข้อมูลได้เลย เช่น join, avg, etc...
ในฐานะที่พวกพี่ๆ มีความชำนาญในการเขียนโปรแกรม
อยากทราบว่าการกระทำการบนฐานข้อมูลแล้วได้ข้อมูลที่ประมวลแล้ว กับการดึงข้อมูลดิบมาประมวลผลเอง
แบบไหนจะมีประสิทธิภาพในแง่ของความเร็ว ขีดจำกัด หรือแง่อื่นๆ มากกว่ากันครับ
ขอบคุณครับ

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

ที่ต้องควรระวังคือเรื่อง database round trips นะครับ
อะไรที่มันดึงมาได้ในคราวเดียวก็ทำให้ได้ใน query เดียวจะดีกว่า ยกเว้นแต่ plan ไว้ว่าจะทำ lazy load

ส่วนจะเอาไปคำนวณที่ไหนเนี่ยก็แล้วแต่การออกแบบครับ บางโปเจ็คออกแบบเน้นทำ store procedure ก็ยัดๆลงไปใน query นั่นแหละ (แต่ query ความยาวเป็นพันบรรทัดนี่เป็นอะไรที่เจ็บปวดมากเวลาต้องมานั่งแก้)

ส่วนตัวผมก็จะดูก่อนว่าถ้าคำนวณไม่ซับซ้อนมากก็ใส่ใน query ครับ
แต่ถ้าซับซ้อนมากเขียนเป็น query ลำบากก็เขียนในโค๊ด

ตอบแบบภาพรวมคร่าวๆ

ทำใน sql มักจะช้ากว่าเอามาคิดเองครับ

แต่สุดท้ายก็ต้องดูอยู่ดีว่าทำคำสั่งอะไร แล้วฝั่งโปรแกรมใช้ภาษาอะไร

ผมว่า SQL เร็วกว่านะครับ มันผ่านการ optimize มาอย่างยิ่งยวดแล้ว
ไม่นับว่าต้องดึงข้อมูลดิบมาส่งผ่านเน็ตเวิร์คแล้วต้องมาประมวลผลอีก

ถ้าดึงมาประมวลผลเพื่อแสดงข้อมูล และสูตรซับซ้อน ดึงมาประมวลที่ client ดีกว่าครับ
แต่ถ้าดึงมาประมวลแล้ว update กลับไปที่ Database ใช้ store procedure

ถ้าแสดงผลข้อมูลจาก procedure ได้เลย เวลาแก้ไขมันก็ทำได้ง่ายเพราะแก้ที่ sql ได้โดยตรง
แต่ถ้าแก้ไขการแสดงผลจากโปรแกรมมันต้อง rebuild ใหม่

อย่างที่หลายท่านแนะนำมาครับ

นอกจากนี้อาจต้องดูปัจจัยอื่นๆ เช่น tuning indexs ความถี่ของการใช้งาน ขนาดข้อมูลที่ต้องประมลวผล
ถ้าทำด้วย SQL แล้วประสิทธิภาพยังใช้ได้ (อย่าให้เกิน 0.01 วินาที) ก็ลุย SQL ตรงๆ ครับ มันมีเรื่อง caching อีกด้วย ที่จะลดการคำนวณที่ไม่จำเป็นลงได้อีก