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()