繁体   English   中英

多个表的最后记录postgres?

[英]last records from multiple tables postgres?

我有两个表“设备”和“校准”,在“设备”中有一些值,在“校准”中有一些值,但是我需要每个表的最后一条记录,我正在尝试执行以下操作:

select concat_ws(',',sim, simfile,txtlaser,txtflow)
from ( select "chkSimulation" as sim, 
      "txtSimFile" as simfile, 
      "txtLaserPower" as txtlaser, "txtRegularFlow" as txtflow from 
     "Devices","Calibrations" order by "Calibrations"."ID" desc limit 1) res;

但这并不能保证我得到设备表的最后一条记录,而只有校准表的最后一条记录。

编辑:我这样做了,但是我得到的结果是每列中有两列,它具有每个表中两个变量中的每个变量,用逗号分开,我如何将所有四个变量合在一起?

select (select concat_ws(',',sim, simfile)
from (select "chkSimulation" as sim, "txtSimFile" as simfile 
    from "Devices" order by "ID" desc limit 1) res), 

(select concat_ws(',',txtpower, flow)
from (select "txtLaserPower" as txtpower, "txtRegularFlow" as flow
    from "Calibrations" order by "ID" desc limit 1)restwo) 
from "Devices", "Calibrations" limit 1
SELECT
  CONCAT_WS(',', sim, simfile, txtlaser, txtregflow)
FROM
  (SELECT
    chkSimulation AS sim,
    txtSimFile AS simfile
  FROM
    Devices
  ORDER BY
    ID DESC
  LIMIT 1) resone,
  (SELECT
    txtLaserPower AS txtlaser,
    txtRegularFlow AS txtregflow
  FROM
    Calibrations
  ORDER BY
    ID DESC
  LIMIT 1) restwo

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM