Sql 如何连接两个提取的列?

Sql 如何连接两个提取的列?,sql,oracle,Sql,Oracle,我需要显示某人已签入的总时间、天数和小时数 下面的代码在单独的列中创建变量,除了列标题之外没有标识符。我还可以创建一个列来显示总小时数 select id, fname, lname, othertablevariable, extract(day from diff) Days, extract(hour from diff) Hours from( select id, fname, lname, othertablevariable, (CAST(checkout as timestamp

我需要显示某人已签入的总时间、天数和小时数

下面的代码在单独的列中创建变量,除了列标题之外没有标识符。我还可以创建一个列来显示总小时数

select id, fname, lname, othertablevariable,
extract(day from diff) Days,
extract(hour from diff) Hours
from(
select id, fname, lname, othertablevariable,
(CAST(checkout as timestamp)-CAST(checkin as timestampe)) diff
from table t1, table t2
where t1.id=t2.id);
输出结果如下:

id fname lname days hours
但是,我希望days列和hours列是单个列


理想情况下,它可以显示为
4天3小时
。这可能吗?

您可以使用内部查询来实现它。检查以下答案:

select id, ..., Days || Hours ConcatenatedColumn
from
(
    select id, fname, lname, othertablevariable,
    extract(day from diff) Days,
    extract(hour from diff) Hours
    from(
    select id, fname, lname, othertablevariable,
    (CAST(checkout as timestamp)-CAST(checkin as timestampe)) diff
    from table t1, table t2
    where t1.id=t2.id)
)

您可以使用以下功能来实现:

select id, fname, lname, othertablevariable,
       CONCAT(extract(day from diff), ' days ', extract(hour from diff), ' hours') AS dayshours
from (
....

结果将是
X天Y小时

今天的提示:切换到现代的显式
JOIN
语法。更易于写入(无错误),更易于读取(和维护),并且在需要时更易于转换为外部联接。(向我们展示一些示例表数据和预期结果。这看起来不错。现在我已经编写了select id,,,Days | | |'Days'| | | | Hours串联列。如何使列显示数据,例如:1天3小时(我只能说1天3小时)无需担心我得到了它Days | | |'Days'| | Hours | |'Hours:)非常感谢!