สอน SQL เบื้องต้น: การเชื่อมแถวในตารางเดียวกัน (SELF JOIN)

Поделиться
HTML-код
  • Опубликовано: 17 окт 2024

Комментарии • 6

  • @parakorntantapon9391
    @parakorntantapon9391 5 лет назад +1

    หามานานมากดลยครับอาจารย์ ต้องคอย insert เข้า table อื่นก่อนตลอดเลย

  • @ittiponpsd4854
    @ittiponpsd4854 11 месяцев назад

    ขอบคุณมากครับ อาจารย์❤

  • @parakorntantapon9391
    @parakorntantapon9391 5 лет назад

    อาจารย์ครับ sql2000 ไม่มี with ต้องเขียนยังไงครับ

    • @prasertcbs
      @prasertcbs  5 лет назад +1

      ใช้ view ครับ

    • @parakorntantapon9391
      @parakorntantapon9391 5 лет назад

      @@prasertcbs อาจารย์ครับ ผมเขียนประมาณนี้ยัง Error ครับ
      create view cte as(select group_no,group_name,a.item,item_desc,item_desc_secondary,type_adj,sum(total_cost) tt_cost
      from zTW_2019 a,item_master b,reason_adj c
      where mm = '9'
      and tran_code in ('22','23')
      and gl_ref_no in ('11','13','911','913')
      and a.item in (select item from item_)

      --join table
      and a.item = b.item and a.gl_ref_no = c.code
      group by group_no,group_name,a.item,item_desc,item_desc_secondary,type_adj)
      select ac.group_no,ac.group_name,ac.item,ac.item_desc,ac.item_desc_secondary,ac.tt_cost [Damage],ac.tt_cost [Expire]
      from cte ac inner join cte ad on ac.item = ad.item and ac.type_adj = '1Damage' and ad.type = '3Expire'

  • @meemeexaiy7467
    @meemeexaiy7467 3 года назад

    ขอชื่อของโปรแกรมหน่อย