Mysql减法用2表

时间:2015-12-10 02:11:25

标签: mysql subtraction

需要你的MySQL帮助。我如何编写下面的查询。

目标:总结每个库存物品的总进货量,总出货量和总出货量。平衡。

我尝试过但无法工作

SELECT
part_db.part_num,
part_db.variant,
SUM(uts_details.qty) AS UTS,
SUM(sir_details.qty) AS SIR,
(UTS - SIR) AS bal
FROM part_db
LEFT OUTER JOIN uts_details ON part_db.part_num = uts_details.part_num
LEFT OUTER JOIN sir_details ON part_db.part_num = sir_details.part_num
GROUP BY part_db.part_num

输出:字段列表中的未知列'UTS'

我这里有3张桌子,

Part_db(零件数据库)

  • Part_num(主键)
  • 变体

Uts_details(Incoming)

  • Uts_no(主键)
  • PART_NUM
  • 数量

Sir_details(传出)

  • Sir_no(主键)
  • PART_NUM
  • 数量

输出: -

part_num: 12345 variant: ABC total_uts: 400 total_sir: 300 (total_uts - total_sir): 100

输出应显示有和没有交易的所有部分。

感谢您的帮助。谢谢!

1 个答案:

答案 0 :(得分:1)

您无法在同一struct page_frame{ struct page_frame* next; //Next node of linked list int used; }; struct page_frame* memBlocks; memBlocks = (struct page_frame*)0xffffffff80000000 + physFree; int indices = ((int)physEnd/4096) for(int i = 0; i < indices; i++) { struct page_frame temp; temp.used = 3; temp.next = (struct page_frame*)&memBlocks[i+1]; memBlocks[i] = temp; } 语句中引用列别名。这是另一种选择:

string scriptpath = @"c:\scripts\emailtooltest.ps1";

        RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
        Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
        runspace.Open();
        RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);

        Pipeline pipeline = runspace.CreatePipeline();
        Command execPS = new Command(scriptpath);
        pipeline.Commands.Add(execPS);
        var results = pipeline.Invoke();

        Console.Read();