sql >> データベース >  >> RDS >> PostgreSQL

PostgresNOSQLjsonデータのjson配列の合計を取得します

    これは9.3以降で機能するはずです

    WITH x AS( SELECT
    '{
      "id": "tran_6ac25129951962e99f28fa488993",
      "amount": 1200,
      "origin_amount": 3900,
      "status": "partial_refunded",
      "description": "Subscription#sub_a67d59efb2bcbf73485a ",
      "livemode": false,
      "refunds": [
        {
          "id": "refund_ee4192ffb6d2caa490a1",
          "amount": 1200,
          "status": "refunded",
          "created_at": 1426412340,
          "updated_at": 1426412340
        },
        {
          "id": "refund_0e4a34e4ee7281d369df",
          "amount": 1500,
          "status": "refunded",
          "created_at": 1426412353,
          "updated_at": 1426412353
        }
      ]
    }'::json as y),
    refunds AS(
    SELECT json_array_elements(y->'refunds') as j FROM x)
    SELECT sum((j->>'amount')::int) FROM refunds;
    


    1. MySQL DATETIME精度(joda-time、Hibernate、org.jadira.usertype、hbm2ddl)

    2. MySQL :(製品)価格に適した列タイプ?

    3. mysqlのint(11)の列のサイズは何バイトですか?

    4. 更新後に以前の値を取得する-MySql