zoukankan      html  css  js  c++  java
  • 大二下学期第一次结对作业(第二阶段)

    上次写的查询完成了一些基本功能,但是里面有许多bug,很多情况没有考虑周全:

    首先看表结构:两个表,分别为details,world

     由于世界疫情和中国疫情是分别爬取的,所以查询时要根据情况查询不同的表,上次的查询没有考虑到。

    world里没有中国的数据,所以查询中国时要在details表里。

    当查询时只填了“中国”,那么我们希望查出的是各省各日期的情况。当填了省份或市区时,我们才展示各市的情况。

    由于details表结构的特殊,查市区与省份时比较容易,但是查中国时,我们不但要将各市区的数据加起来变为省的数据,还要按时间分开。

    "select update_time,province,sum(confirm),sum(heal),sum(dead) from details where (update_time between ds and  ds1 )group by province , update_time"

    这就是基本的查询语句,但是根据不同的情况还要进行不同的修改:

    if(province!="" or city!="" or country=="中国"):
            sql = "select update_time,province,sum(confirm),sum(heal),sum(dead) from details " 
                  "where (update_time between " + "'" + ds + "' and '" + ds1 + "'" + ") "
            if (province != "" and city ==""):
                sql="select update_time,province,city,confirm,heal,dead from details " 
                  "where (update_time between " + "'" + ds + "' and '" + ds1 + "'" + ") "
                sql = sql + "and (province like " + '"%' + province + '%") '
            if (province!="" and city != ""):
                sql = "select update_time,province,city,confirm,heal,dead from details " 
                      "where (update_time between " + "'" + ds + "' and '" + ds1 + "'" + ") "
                sql = sql + "and (city like " + '"%' + city + '%") '
                sql = sql + "and (province like " + '"%' + province + '%") '
            if(country=="中国" and province=="" and city==""):
                sql=sql+"group by  province , update_time"
        if(province=="" and city=="" and country!="中国"):
            sql = "select update_time,country,confirm,heal,dead,nowconfirm from world " 
                  "where (update_time between " + "'" + ds + "' and '" + ds1 + "'" + ") "
            if (continent != ""):
                sql = sql + "and (continent like " + '"%' + continent + '%") '
            if (country != ""):
                sql = sql + "and (country like " + '"%' + country + '%") '
        print("查询(带日期)")
        print(sql)
        res = query(sql)
  • 相关阅读:
    Chrome DevTools(开发者工具) 全攻略
    vue中使用echarts实现疫情地图
    VUE项目在IE上控台报错,无法进入项目或无法页面跳转
    <script>标签的属性
    CSS实现网页变灰的效果
    HTTP之缓存命中
    HTTP之缓存处理步骤
    HTTP之Web服务器是如何进行工作的!
    HTTP之URL的快捷方式
    HTTP之URL的组成部分
  • 原文地址:https://www.cnblogs.com/fengchuiguobanxia/p/14593445.html
Copyright © 2011-2022 走看看