zoukankan      html  css  js  c++  java
  • Flask04-SQL

    from flask import render_template, flash, redirect
    from app import app
    from app import db, models
    from forms import LoginForm, SheetForm, VulForm, EveForm
    import datetime
    import time
    
    
    // 原始SQL       
    select sheet.name,count(*) from vul inner join sheet on vul.sheet_id = sheet.id group by sheet.name;
    
    // join操作
    vuls_count = models.Vul.query.join(models.Sheet,
                 models.Vul.sheet_id==models.Sheet.id) 
                 .add_columns(models.Sheet.name)
    
    // group操作
    vuls_count.query(models.Sheet.name, func.count('*')) 
              .group_by(models.Sheet.name).all()
    
    // join操作 加 group操作
    vuls_count = models.Vul.query.join(models.Sheet,
                 models.Vul.sheet_id==models.Sheet.id) 
                 .add_columns(models.Sheet.name, func.count('*')).group_by(models.Sheet.name).all()
    
    vul_count = models.Vul.query.filter_by(sheet_id=1).add_columns(models.Vul.level, func.count("*")).group_by(models.Vul.level).all()
  • 相关阅读:
    0601 新的冲刺
    0527 演示内容
    0525 项目回顾7.0
    0523 Scrum项目6.0
    0518 Scrum项目5.0
    Scrum 4.0
    0512 操作系统进程调度实验
    0511 backlog 项目管理
    复利计算器之单元测试
    操作系统的实验一实验报告
  • 原文地址:https://www.cnblogs.com/mlsec/p/8595279.html
Copyright © 2011-2022 走看看