当某个条件在另一个表中匹配时,从一个表中查找值

时间:2018-06-18 15:27:54

标签: postgresql postgresql-9.3 pgadmin pgadmin-4

我有两张桌子,Shifts Usercomps

班次有4列Id,Shiftname,Shiftstart,Shiftfinish

ID是串行主键

Shiftname Charactor(20)

Shiftstart&没有时区的shiftfinish时间

Usercomp有24列,但感兴趣的列是Shiftid shiftstart,shiftfinish

Shiftid是不同的角色

Shift start& Shiftfinish是没有时区的时间。

我需要在Usercomp表中的Shiftid中输入数据以查找移位表中Id列上的值,即1,然后在shiftcompart的shiftstart和shiftfinish colums中显示Shiftstart和shiftfinish数据。

我已经开始创建一个代码来执行shiftstart:

names=# INSERT INTO public."Usercomp"("Shiftstart")
names-# SELECT "Shiftstarttime"
names-# FROM public."Shifts"
names-# WHERE "Id" = public."Usercomp"("Shiftid"); 

但是有以下错误:

ERROR:  column "Shiftid" does not exist
LINE 4: WHERE "Id" = public."Usercomp"("Shiftid");
                                       ^
HINT:  There is a column named "Shiftid" in table "Usercomp", but it cannot be referenced from this part of the query.

任何人都可以帮我尝试这项工作吗?

0 个答案:

没有答案