Mysql查询耗时

发布于 2024-10-04 17:42:05 字数 839 浏览 4 评论 0原文

Qe : 1)

select 
  a.finishproductid 
from 
  tblt_invoiceorderitems a, tblm_invoiceorder b 
where 
  b.invoiceorderdate <= 'Current Date' and 
  a.invoiceorderid = b.invoiceorderid 

--- 它有超过 16k 条记录。

Qe : 2 )

select jobcardid, stockcode 
from tblm_finishproduct 
where productionentrydate <= 'Current Date'

--- 它也有超过 16k 条记录。

现在我想要来自第二个查询而不是第一个查询。

select jobcardid, stockcode 
from 
  tblm_finishproduct 
where 
  productionentrydate <= 'CurrrntDate' and 
  finishproductid not in 
  (
    select 
      a.finishproductid 
    from 
      tblt_invoiceorderitems a, tblm_invoiceorder b 
    where 
      b.invoiceorderdate <= 'CurrrntDate' and 
      a.invoiceorderid = b.invoiceorderid
  );

现在需要一些时间

Qe : 1)

select 
  a.finishproductid 
from 
  tblt_invoiceorderitems a, tblm_invoiceorder b 
where 
  b.invoiceorderdate <= 'Current Date' and 
  a.invoiceorderid = b.invoiceorderid 

--- it has more than 16k records.

Qe : 2 )

select jobcardid, stockcode 
from tblm_finishproduct 
where productionentrydate <= 'Current Date'

--- it has also more than 16k Record.

Now i Want From 2nd Query not in first query.

select jobcardid, stockcode 
from 
  tblm_finishproduct 
where 
  productionentrydate <= 'CurrrntDate' and 
  finishproductid not in 
  (
    select 
      a.finishproductid 
    from 
      tblt_invoiceorderitems a, tblm_invoiceorder b 
    where 
      b.invoiceorderdate <= 'CurrrntDate' and 
      a.invoiceorderid = b.invoiceorderid
  );

Now its taking a time

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迟到的我 2024-10-11 17:42:05

这并不能解决您的问题,但您不应该在 where 子句中使用 a.invoiceorderid = b.invoiceorderid - 尝试用此查询代替第一个查询。 自然连接比进行叉积更有效整个表并仅选择那些匹配的行。

select a.finishproductid 
from tblt_invoiceorderitems a 
natural join tblm_invoiceorder b 
where b.invoiceorderdate <= 'Current Date'

This does not address your question, but you should not be using a.invoiceorderid = b.invoiceorderid in your where clause--try this query in place of the first one. Natural join is more efficient than making a cross product of the entire table and selecting only those rows that match.

select a.finishproductid 
from tblt_invoiceorderitems a 
natural join tblm_invoiceorder b 
where b.invoiceorderdate <= 'Current Date'
阿楠 2024-10-11 17:42:05

将其从 not in 中删除:

b.invoiceorderdate <= 'CurrrntDate' and

Remove this from the not in:

b.invoiceorderdate <= 'CurrrntDate' and
吝吻 2024-10-11 17:42:05

“select Table1, Table2, Table3”的结果可能是 16k^3 或 16k^2。您需要使用主键进行“内部联接”或“联接”来计算搜索。

再见。

the result of "select Table1, Table2, Table3" maby is 16k^3 or 16k^2. You need make a "inner join" or "join" using primary key to cout the search.

See u.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文