search

Home  >  Q&A  >  body text

mysql - 需要insert或者update的字段是随机的,如何拼接sql语句

有个问题请教下大伙。
有一张表,有很多个字段,每次都是随机的几个的字段需要根据收到的报文进行insert或者update,这句sql语句应该怎么样拼接呢?
报文的格式如下,["字段名",“值”]

['num', '01'], ['time', '20150227152120'], ['cccttt', '18.2'], ['cccuuu', '78'], ['ccctdd', '14.3'], ['cccppp', '1014.87'], ['cccqfe', '1014.5'], ['cccqnh', '1016.4'], ['cccprr', '0.0'], ['ccc1prr', '0.0'], ['ccc60prr', '0.0'], ['ccc60prrtime', '00'], ['ccc1maxfs', '5.0'], ['ccc1minfs', '2.2'], ['cccprevailfs', '3.0'], ['cccprevailfx', '120'], ['ccc24maxfs', '8.8'], ['ccc24maxfx', '120'], ['ccc24maxfstime', '12:35'], ['ccc24minfs', '1.2'], ['ccc24minfx', '120'], ['ccc24minfstime', '04:45'], ['cccmaxrh', '99'], ['cccmaxrhtime', '00:55'], ['cccminrh', '78'], ['cccminrhtime', '15:01'], ['npd', '04L'], ['light', '3']

每条报文的长度都是随机的。

巴扎黑巴扎黑2786 days ago654

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 11:57:57

    key, value, determine whether the primary key id is present, if not, it means insert, if it is, it means update

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 11:57:57

    If you have a primary key, use the
    insert or update statement, which is also very convenient

    reply
    0
  • Cancelreply