如何在postgres中查找月份的最后一天?我有一个日期列存储为数字(18)格式(YYYYMMDD)我正在尝试使其使用日期
to_date("act_dt",'YYYYMMDD') AS "act date"
Run Code Online (Sandbox Code Playgroud)
然后找到这个日期的最后一天:像这样:
(select (date_trunc('MONTH',to_date("act_dt",'YYYYMMDD')) + INTERVAL '1 MONTH - 1 day')::date)
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误:
ERROR: Interval values with month or year parts are not supported
Detail:
-----------------------------------------------
error: Interval values with month or year parts are not supported
code: 8001
context: interval months: "1"
query: 673376
location: cg_constmanager.cpp:145
process: padbmaster [pid=20937]
-----------------------------------------------
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
Postgres版本:
PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.874
我在SQL Server中有这样的查询
Alter table inventory
Add totalitems as iteminstore + iteminwarehouse PERSISTED`
Run Code Online (Sandbox Code Playgroud)
写这个有persisted什么好处?
我正在使用SQL Server 2012。
定义是:
WITH VIEW_METADATA
指定后,将返回视图的元数据而不是基表
这是查询:
alter view dbo.sales(vi)
with view_metadata
as
select o.[SalesOrderID]
from [Sales].[SalesOrderHeader] o
select * from dbo.sales
Run Code Online (Sandbox Code Playgroud)
返回值:
vi
43698
43699
43700
43701
Run Code Online (Sandbox Code Playgroud)
当更改为时WITH SCHEMABINDING也会产生相同的结果。
有人可以告诉我的含义WITH VIEW_METADATA以及它与其他视图选项的不同之处吗?
我正在使用SQL Server 2012。
我的表定义:
create table cust
(
cid int identity,
cnm varchar(100),
country varchar(100)
)
alter table cust
add constraint pk primary key clustered on cust(cid)
Run Code Online (Sandbox Code Playgroud)
我试图仅在更新cnm或country列时创建审核记录。
我的2个查询:
create trigger trig_nm on cust
as
if columns_updated(cnm, country)
--create records.
create trigger trig_nm on cust
as
if update(cnm) or update(country)
--create records.
Run Code Online (Sandbox Code Playgroud)
2个查询之间有什么区别?
我正在使用 sql-server 2012:
drop table ttt
create table ttt(id int,amt int)
insert into ttt values(1,100),(2,200),(1,200),(3,400),(1,500)
create function dbo.t1(@id int)
returns int
with returns null on null input
as
begin
declare @amt_total int
select @amt_total=sum(amt) from ttt
where id=@id
return @amt_total
end
select t.id,t.amt,f.id from ttt t cross apply dbo.t1(t.id) f
Run Code Online (Sandbox Code Playgroud)
该代码在执行时返回以下错误:
Msg 208, Level 16, State 3, Line 16
Invalid object name 'dbo.t1'.
有什么帮助吗?
函数、表都存在于同一模式中