如何在SQL中显示外国钥匙值,而不是其ID-S
我在制作日历时遇到了问题。我有一个名为rezervacije
(预订)的表格,带有name
,start date
,结束日期
,等。 ;还有recervation_type_fk
,将其连接到另一张表格的外键,其中保留类型是用名称,价格等列写下的。
现在我的问题是:
我如何显示保留名称类型而不是ID-S? 我当前的SQL查询是这样的:
select
ID_REZ, /*ID of the reservation, number goes up by 1 on every insert automatically generated*/
START_REZ, /*DATE OF THE START OF THE RESERVATION*/
END_REZ, /*DATE OF THE END OF THE RESERVATION*/
DETAILS_REZ, /*VARCHAR2 - comments on the reservation*/
case
when DETAILS_REZ is not null
then title || '[' || QUANTITY_REZ || 'x ' || /*HERE I WANT TO DISPLAY THE FK NAME*/
|| ' hours on ' || NUMBER_OF_HOURS || ' - ' || DETAILS_REZ || ' ]'
end as title,
QUANTITY_REZ, /* NUMBER Quantity of things on the reservation */
NUMBER_OF_HOURS, /*NUMBER of hours of the reservation calculated automatically*/
case
when REZ_TYPE_FK = 8
then 'apex-cal-red' /*THIS FK is a number
Identity: always, in increments of 1 that connects to another table that has a name price etc and is saved in my RESERVATION table as a foreign key and I don't want to display it as a number but as a name of the RESERVATION TYPE*/
when REZ_TYPE_FK = 9 then 'apex-cal-orange'
when REZ_TYPE_FK = 10 then 'apex-cal-blue'
when REZ_TYPE_FK = 11 then 'apex-cal-green'
when REZ_TYPE_FK = 12 then 'apex-cal-lime'
end as CSS_REZ /*Varchar2 that paints my calendar entries to a certain color */
from
REZERVACIJE
where
(nvl(:REZ_TYPE_OBJ,'0') = '0' or REZ_TYPE_FK = :REZ_TTYPE_OBJ) /* This is for a LOV selection where i can filter what RESERVATION TYPE i want to see*/
order by
START_REZ
因此,我只想在标题中显示预订类型
的名称。我知道这是一个新秀问题,可能很简单,但是请耐心,因为我才刚刚开始。
I encountered a problem while making a calendar. I have a table named REZERVACIJE
(reservations) with columns like name
, start date
, end date
, etc.; and also a reservation_type_FK
, a foreign key that connects it to another table where reservation types are written down with columns like name, price, etc.
Now my question is:
How do I show the name of the reservation types instead of the ID-s?
my current SQL query is like this:
select
ID_REZ, /*ID of the reservation, number goes up by 1 on every insert automatically generated*/
START_REZ, /*DATE OF THE START OF THE RESERVATION*/
END_REZ, /*DATE OF THE END OF THE RESERVATION*/
DETAILS_REZ, /*VARCHAR2 - comments on the reservation*/
case
when DETAILS_REZ is not null
then title || '[' || QUANTITY_REZ || 'x ' || /*HERE I WANT TO DISPLAY THE FK NAME*/
|| ' hours on ' || NUMBER_OF_HOURS || ' - ' || DETAILS_REZ || ' ]'
end as title,
QUANTITY_REZ, /* NUMBER Quantity of things on the reservation */
NUMBER_OF_HOURS, /*NUMBER of hours of the reservation calculated automatically*/
case
when REZ_TYPE_FK = 8
then 'apex-cal-red' /*THIS FK is a number
Identity: always, in increments of 1 that connects to another table that has a name price etc and is saved in my RESERVATION table as a foreign key and I don't want to display it as a number but as a name of the RESERVATION TYPE*/
when REZ_TYPE_FK = 9 then 'apex-cal-orange'
when REZ_TYPE_FK = 10 then 'apex-cal-blue'
when REZ_TYPE_FK = 11 then 'apex-cal-green'
when REZ_TYPE_FK = 12 then 'apex-cal-lime'
end as CSS_REZ /*Varchar2 that paints my calendar entries to a certain color */
from
REZERVACIJE
where
(nvl(:REZ_TYPE_OBJ,'0') = '0' or REZ_TYPE_FK = :REZ_TTYPE_OBJ) /* This is for a LOV selection where i can filter what RESERVATION TYPE i want to see*/
order by
START_REZ
So I just want to show in the title the name of the RESERVATION TYPE
from the other table. I know this is such a rookie question and is probably very simple but please have patience because I just started.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
带有以下假设:
reservation_types
带有主键reservation_type_id
以及需要显示的列为reservient_type_type_name
rezervacije.rez_type_fk
始终具有一个值。选择将是:
用实际的表/列名称替换假设(1)中的值。如果假设(2)不正确,则您将无法获得具有
r.rez_type_fk
的null值的记录的行。将更改为
如果要所有记录,请左Out Out Join 。With the following assumptions:
RESERVATION_TYPES
with primary keyRESERVATION_TYPE_ID
and the column that needs to be displayed isRESERVATION_TYPE_NAME
REZERVACIJE.REZ_TYPE_FK
always has a value.The select would be:
Replace the values in assumption (1) with the actual table/column names. If assumption (2) is incorrect you will not get a row for records that have a NULL value for
R.REZ_TYPE_FK
. ChangeJOIN
toLEFT OUTER JOIN
if you want all the records.这是加入最简单的用例
This is the most simple use case for JOIN