zoukankan      html  css  js  c++  java
  • 增加两个字段、 sql先查找、 在比较、然后更新、

    #重点是需要递交、conn.commit()   不要忘记关闭


    import requests
    from lxml import etree
    import psycopg2



    def sql_cunchu():
    conn = psycopg2.connect(database="mapwayonline", user="postgres", password="C02SP70YGF1J", host="47.92.116.107", port="5434")
    cur = conn.cursor()

    #世界500强
    # cur.execute("select name,index from bjzs_big_data.baoji_company_top where id > 2463 and isworld = 1;")
    # rows = cur.fetchall()
    # for world in rows:
    # print(world[0],world[1])


    #国内500强
    # cur.execute("select name,index from bjzs_big_data.baoji_company_top where id > 2463 and ischina = 1;")
    # rows = cur.fetchall()
    # j = 1
    # for china in rows:
    # print(china[0], china[1])
    # print(j)
    # j += 1


    #已经存在的500强 名字、
    # cur.execute("select name from bjzs_big_data.baoji_company_top where tyc_id is null and qcc_id is null and id < 2463")
    # rows = cur.fetchall()
    # m = 1
    # for exist in rows:
    # existcomp = exist[0]
    # print(exist[0])
    # print(m)
    # m += 1


    #已经存在的500强 名字、
    cur.execute(
    "select name from bjzs_big_data.baoji_company_top where tyc_id is null and qcc_id is null and id < 2463")
    rows = cur.fetchall()
    for exist in rows:
    existcomp = exist[0]

    #世界500强
    cur.execute("select name,index from bjzs_big_data.baoji_company_top where id > 2463 and isworld = 1")
    world_rows = cur.fetchall()

    for world in world_rows:
    print(world[0], world[1])
    if world[0] == existcomp:
    #更新原来帆帆定的空索引
    cur.execute("UPDATE bjzs_big_data.baoji_company_top SET index_isworld = %s WHERE tyc_id is null and qcc_id is null and id < 2463 and name = %s",(world[1], existcomp))
    conn.commit()


    #中国500强
    cur.execute("select name,index from bjzs_big_data.baoji_company_top where id > 2463 and ischina = 1")
    china_rows = cur.fetchall()
    for china in china_rows:
    print(china[0], china[1])
    if china[0] == existcomp:
    cur.execute("UPDATE bjzs_big_data.baoji_company_top SET index_ischina = %s WHERE tyc_id is null and qcc_id is null and id < 2463 and name = %s",(china[1], existcomp))
    conn.commit()


    #print(exist[0])

    conn.commit()
    cur.close()
    conn.close()

    if __name__ == '__main__':
    sql_cunchu()

  • 相关阅读:
    winform中的 listview的使用的讲解。
    快乐的一天从AC开始 | 20210716 | P1345
    快乐的一天从AC开始 | 20210715 | P4643
    快乐的一天从AC开始 | 20210714 | P3594
    快乐的一天从AC开始 | 20210713 | P3557
    快乐的一天从AC开始 | 20210712 | P2251
    P7294-[USACO21JAN]Minimum Cost Paths P【单调栈】
    AT4353-[ARC101D]Robots and Exits【LIS】
    2021牛客暑期多校训练营9C-Cells【LGV引理,范德蒙德行列式】
    Loj#2880-「JOISC 2014 Day3」稻草人【CDQ分治,单调栈,二分】
  • 原文地址:https://www.cnblogs.com/yuanjia8888/p/10238045.html
Copyright © 2011-2022 走看看