• Giúp tạo 1 query in ra dòng cuối dữ liệu của 1 table
  • Giúp tạo 1 query in ra dòng cuối dữ liệu của 1 table

    thienphuct > 22-10-15, 04:06 PM

    chỉ em với
  • RE: Giúp tạo 1 query in ra dòng cuối dữ liệu của 1 table

    thucgia > 22-10-15, 06:38 PM

    (22-10-15, 04:06 PM)thienphuct Đã viết: chỉ em với

    1, Đầu vào

    Mã:
    id ten don_gia solg
    aaa Muối 1 1
    bot Bot 100 1
    duong Duong 100 1
    sua Sua 200 1


    2,Đầu ra

    Mã:
    id ten don_gia solg stt

    sua Sua 200 1 4


    3, Làm thế nào

    Mã:
    select * from
    (

    select a.*,
    (select count(*) from hang where a.id>=id) as stt
    from hang as a

    )
    as t1
    where t1.stt=
    (
      select so_max from

      (

    SELECT Max(t1.stt) AS so_max
    FROM t1

      )
      as t2

    )