简体   繁体   English

修改列和行中的值 (PSQL)

[英]Modify values within a column and row (PSQL)

I get the following error for this query: [22P02] ERROR: invalid input syntax for type numeric: "."我收到此查询的以下错误:[22P02] 错误:数字类型的输入语法无效:“。”

select 
date,
row_number () over () as RN,
case when (row_number() over ()) ='8' then '.' else (success/trials) end as "After_1M"
from trials
groupy by date;

Is there another way to indicate that a certain value in a ROWxCOLUMN combination should be adjusted?是否有另一种方法表明应该调整 ROWxCOLUMN 组合中的某个值?

Well your description certainly leaves a lot to be desired.那么你的描述肯定有很多不足之处。 But your query only needs slight modification to actually run.但是您的查询只需要稍作修改即可实际运行。 First off "groupy by date".首先是“按日期分组”。 I will assume it's just a typo.我会假设这只是一个错字。 But a group by without an aggregate function generally doesn't do anything - and this is one of those.但是没有聚合 function 的组通常不会做任何事情——这就是其中之一。 But I believe your attempting to get a row count by date.但我相信您试图按日期计算行数。 If so the you need the partition by and order by clauses in the in the row_number function.如果是这样,您需要 row_number function 中的 partition by 和 order by 子句。 The other issue is in the expression.另一个问题是表达式。 Each entry in the expression must return the same data type but in case it doesn't.表达式中的每个条目都必须返回相同的数据类型,但以防万一。 The THEN condition returns character (.) while the ELSE returns a numeric (success/trials) which must define 2 numeric columns to be valid. THEN 条件返回字符 (.) 而 ELSE 返回一个数字(成功/试验),它必须定义 2 个数字列才有效。 So which needs to change?那么哪些需要改变呢? I will assume the later.我会假设后者。 Given this we wind up with:鉴于此,我们最终得到:

select date
    , row_number() over(partition by date order by trl_date) rn
    , case when (row_number() over(partition by date order by trl_date)) = 8
           then '.' 
           else (success/trials)::text
      end as  "After_1M"
 from trials;

Note: Date is a very poor date is a very poor column name.注意:日期是一个很差的日期是一个很差的列名。 It's a reserved word , as well as a data type.它是一个保留字,也是一种数据类型。

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

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