简体   繁体   English

如何在查询结果中添加时间戳?

[英]How do I add a timestamp to my query results?

I want to add a column to my query results that repeats the current timestamp for all records returned. 我想在查询结果中添加一列,以对返回的所有记录重复当前时间戳。 This would effectively be a column that tells you when the query was executed. 这实际上将是一列,告诉您何时执行查询。

Tried using With, Union, and Join...but it doesn't seem like there's a way to "print" data into sql results that are not already contained in the database. 尝试使用With,Union和Join ...,但似乎没有一种方法可以将数据“打印”到数据库中尚未包含的sql结果中。

Select * from myTable
Union
select current_timestamp

print (select current_timestamp) 打印(选择current_timestamp)

The results would be all of the contents of the table with an extra column that has the current_timestamp for all records returned. 结果将是表的所有内容,并带有一个额外的列,该列具有针对所有返回的记录的current_timestamp。

if you want the current_timestamp on each row resulting form select You should only add the col 如果要在结果表格的每一行上使用current_timestamp,请仅添加列

Select *, current_timestamp  
from myTable

try: 尝试:

Select * from myTable
Union
select current_timestamp as timeStamp

您需要将TIMESTAMP放在select子句中,如下所示-

Select *,current_timestamp from myTable

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

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