Results 1 to 4 of 4

Thread: มีปัญหาที่คำสั่ง Sql ครับ

  1. #1
    Junior Member
    Join Date
    Dec 2006
    Posts
    0


    มีปัญหาที่คำสั่ง Sql ครับ

    select t2.order_no ,t2.paid, t2.invoid_date from test as t2 where t2.paid in
    (select max(t1.paid) from test as t1 group by t1.invoid_date);

    มัน error เพราะอะไรหรือครับ มีคนบอกว่า เอาไปลองใน
    Access แล้วผ่าน แต่ ทำ ใน Mysql มัน Error
    คร่าวๆที่ต้องการคือตอนนี้มี database
    ที่มีอยู่
    ลำดับ--วันที่-------รายได้
    1-------1/2/47----5000
    2-------1/2/47----6500
    3-------1/2/47----4500
    4-------2/2/47----3500
    5-------2/2/47----4000

    ที่อยากได้
    ลำดับ--วันที่------รายได้
    2-------1/2/47--6500
    5-------2/2/47--4000

  2. #2
    Junior Member
    Join Date
    Dec 2006
    Posts
    0


    Re: มีปัญหาที่คำสั่ง Sql ครับ

    (select max(t1.paid) from test as t1 group by t1.invoid_date);
    ต้องเปลี่ยนเป็น
    (select max(t1.paid),t1.invoid_date from test as t1 group by t1.invoid_date);

  3. #3
    Jedi Global Moderator
    Join Date
    Aug 2007
    Location
    Bangkok
    Posts
    136


    http://www.88upload.net/uploads/29b9f20302...e8398b72eb4274a

    ผมลองตาม Code ที่คุณให้มา ใน MySQL v.5.0.54 ผ่าน phpmyadmin ไม่มีปัญหานี่ครับ ก็สั่ง query ได้ปรกติ

    select t2.order_no ,t2.paid, t2.invoid_date
    from test as t2
    where t2.paid in (
    select max(t1.paid)
    from test as t1
    group by t1.invoid_date);

    ไม่ต้องเปลี่ยนนี่ครับ

  4. #4
    Junior Member
    Join Date
    Jun 2009
    Posts
    4


    สามารถใช้ได้สองแบบครับ คือค้นหาด้วยคำสัง where ได้ครับ
    เช่น จากที่คุณ hinalove ได้แสดงให้ดู
    select t2.order_no ,t2.paid, t2.invoid_date from test as t2 where t2.paid in (
    select max(t1.paid)
    from test as t1
    group by t1.invoid_date);


    และอีกแบบคือการ join กันครับ เช่น
    select t1.* from test t1 inner join
    (select invoid_date, max(paid) as paid from test group by invoid_date) as t2
    on t1.paid=t2.paid and t1.invoid_date=t2.invoid_date

Similar Threads

  1. Replies: 1
    Last Post: 14-05-2009, 09:47 PM
  2. Replies: 2
    Last Post: 20-02-2009, 07:05 PM
  3. Replies: 0
    Last Post: 29-01-2008, 05:33 PM
  4. วิธีการแกะรอยหา IP ครับ
    By mastermodradio in forum Hacking, Exploit Articles/Tutorial/Techniques
    Replies: 0
    Last Post: 11-11-2006, 10:13 AM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •