Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

JSON Masukkan ke dalam tabel MySQL atau perbarui jika ada

Skrip berikut dapat berguna untuk kebutuhan Anda:

INSERT INTO `TAG_COUNTER`
  (`account`, `time_id`, `counters`)
VALUES
  ('google', '20180510', '{"gmail_page_viewed": 1, "search_page_viewed": 50}'),
  ('google', '20180510', '{"gmail_page_viewed": 1, "search_page_viewed": 50}'),
  ('google', '20180511', '{"gmail_page_viewed": 1, "search_page_viewed": 100}'),
  ('google', '20180511', '{"gmail_page_viewed": 1, "search_page_viewed": 100}'),
  ('google', '20180511', '{"gmail_page_viewed": 1, "search_page_viewed": 100}')
ON DUPLICATE KEY UPDATE `counters` =
  JSON_SET(`counters`,
           '$."gmail_page_viewed"',
           IFNULL(`counters` ->> '$."gmail_page_viewed"', 0) + 1,
           '$."search_page_viewed"',
           IFNULL(`counters` ->> '$."search_page_viewed"', 0) + 1
  );

Lihat dbfiddle .




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. python — Masalah menyimpan karakter Unicode ke MySQL dengan Django

  2. Apakah ORDER BY berlaku sebelum atau sesudah DISTINCT?

  3. MySQL:Tambahkan kolom urutan berdasarkan bidang lain

  4. Menggunakan OpenVPN untuk Mengamankan Akses ke Cluster Basis Data Anda di Cloud

  5. Hitung kemunculan sub string di kolom MySQL