【问题标题】:Why does the select break off?为什么选择中断?
【发布时间】:2018-04-04 02:58:07
【问题描述】:
select  m.matnr, m.hkl, m.lok_nr from Bestand M,

(select b.matnr, b.hkl, b.lok_nr from BESTAND B, LAGER_LOKATION L
 where ((b.matnr = l.matnr and b.hkl = l.hkl and b.lok_nr = l.lok_nr 
 and b.best_frei = 0 and l.greiflok = 'J' and l.status = 2) or
       (b.matnr = l.matnr and b.hkl = l.hkl and b.lok_nr = l.lok_nr 
 and b.best_frei > 0 and l.greiflok = 'N' and l.status = 2))
) Bedingung_1,


 ( select s.matnr, s.hkl, s.ziel_lok_nr from SONDER_AUFTRAG S, 
  LAGER_LOKATION L2
  where s.matnr = l2.matnr and s.hkl = l2.hkl and s.status = 611 and 
  s.ziel_lok_nr = l2.lok_nr and l2.greiflok ='N'
 ) Bedingung_2

where

m.matnr = Bedingung_1.matnr and m.matnr not in Bedingung_2.matnr
group by m.matnr, m.hkl, m.lok_nr;

【问题讨论】:

  • 今日提示:切换到现代显式 JOIN 语法。更容易编写(没有错误),更容易阅读(和维护),并且在需要时更容易转换为外连接。
  • 在不涉及聚合函数的情况下为什么要使用 GROUP BY?
  • 添加一些示例表数据和预期结果 - 作为格式化文本,而不是图像。 (在您花太多时间之前,请查看stackoverflow.com/help/mcve。)
  • 评论这个'和 m.matnr 不在 Bedingung_2.matnr' 然后尝试。这会运行吗?
  • 为什么选择中断 - 我不知道这是什么意思

标签: mysql sql database


【解决方案1】:
    select  m.matnr, m.hkl, m.lok_nr from Bestand M 
    left join
    (select b.matnr, b.hkl, b.lok_nr from BESTAND B, LAGER_LOKATION L
     where ((b.matnr = l.matnr and b.hkl = l.hkl and b.lok_nr = l.lok_nr 
     and b.best_frei = 0 and l.greiflok = 'J' and l.status = 2) or
           (b.matnr = l.matnr and b.hkl = l.hkl and b.lok_nr = l.lok_nr 
     and b.best_frei > 0 and l.greiflok = 'N' and l.status = 2))
    ) Bedingung_1 on m.matnr = Bedingung_1.matnr
    where
    m.matnr not in 
( select s.matnr from SONDER_AUFTRAG S, 
      LAGER_LOKATION L2
      where s.matnr = l2.matnr and s.hkl = l2.hkl and s.status = 611 and 
      s.ziel_lok_nr = l2.lok_nr and l2.greiflok ='N'
     )
    group by m.matnr, m.hkl, m.lok_nr;

试试这个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-16
    • 2018-07-28
    • 2014-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-24
    • 1970-01-01
    相关资源
    最近更新 更多