【发布时间】:2014-06-14 05:06:54
【问题描述】:
我想在 PostgreSQL 中使用 CASE 语句进行插入。
如果我的结果集计数为零,我正在尝试插入。如果它不等于 0,那么我只想选择该表上的最大时间。
select
case
when (select count(*) from x where TableName = 'p' ) > 0
then
(select MaxDataDate from x where TableName = 'p' )
when (select count(*) from s where TableName = 'p') = 0
then
(insert into x values('p','1900-01-01'))
end
【问题讨论】:
-
请分享一些示例数据,您到底想做什么?
-
你用的是什么数据库引擎,请打个tag,会有帮助的
-
您不能编写选择或插入测试是否验证的查询。您必须测试您的条件,然后执行相关查询。
-
那我该怎么做呢?
-
在那里你应该找到你需要的答案:stackoverflow.com/questions/11299037/postgresql-if-statement
标签: sql postgresql