gpt4 book ai didi

MYSQL > 使用查询作为表

转载 作者:行者123 更新时间:2023-11-29 03:37:33 24 4
gpt4 key购买 nike

我忘记了一个老师告诉我的技巧,它允许 Select 查询成为您的表(假设只有部分数据库用于重复条目)...

THIS_FUNCTION(Select link, things, conditions from OneTable tabA where conditions = IGotSomething)

THIS_FUNCTION(Select link, things, conditions from OneTable tabB where conditions = IlostSomething)

Select tabA.things - tabB.things from tabA inner join tabB on tabA.link = tabB.link

类似的东西。

有人帮我记一下吗?


以防万一有人问...我的数据库使用一个表来存储所有进出的事务,由一列定义,其中有一些内容。要获得所有元素的 list ,我需要查看元素来自何处 (-stock) 以及元素将去往何处 (+stock)。

在某些情况下,它的去向也是它的来源。

我已经知道如何做到这一点,但我需要那个我忘记的技巧......


糟糕!我忘了提到我需要能够在运行时根据用户需求构建这些查询。它是可定制的,因此构建和重建 View 可能会占用比预期更多的进程。

最佳答案

编辑:这是一种方法:

CREATE PROCEDURE this_function()
BEGIN
Select link, things, conditions from OneTable tabA where conditions = IGotSomething;
END

然后:

CALL this_function();

这是另一种方式,但它会在您的数据库中创建新表:

CREATE ALGORITHM = UNDEFINED VIEW `tabA` AS Select link, things, conditions from OneTable tabA where conditions = IGotSomething;

CREATE ALGORITHM = UNDEFINED VIEW `tabB` AS Select link, things, conditions from OneTable tabB where conditions = IlostSomething;

然后:

Select tabA.things - tabB.things from tabA inner join tabB on tabA.link = tabB.link

关于MYSQL > 使用查询作为表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19203985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com