mysql求平均值
表结构:
create table monitor
(
instanceId varchar(100) not null,
date date not null,
cloud varchar(20) not null,
avgCpuUseRatio float null,
primary key (instanceId, date, cloud)
);
#求instanceId对应的avgCpuUseRatio的平均值
select instanceId, AVG(avgCpuUseRatio) from monitor where cloud="Aliyun" and type="ecs" and date>='2018-07-01' and date<= '2018-07-31' group by instanceId;
参考:
https://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_avg
对于python的sqlalchemy可以使用text语法
>>> from sqlalchemy import create_engine
>>> engine = create_engine('sqlite:///:memory:', echo=True)
>>> conn = engine.connect()
>>> from sqlalchemy.sql import text
>>> s = text( ... "SELECT users.fullname || ', ' || addresses.email_address AS title " ... "FROM users, addresses " ... "WHERE users.id = addresses.user_id " ... "AND users.name BETWEEN 😡 AND :y " ... "AND (addresses.email_address LIKE :e1 " ... "OR addresses.email_address LIKE :e2)") SQL
>>> conn.execute(s, x='m', y='z', e1='%@aol.com', e2='%@msn.com').fetchall() [(u'Wendy Williams, wendy@aol.com',)]
参考:http://docs.sqlalchemy.org/en/latest/core/tutorial.html#using-textual-sql
版权声明:本文为qq_21514303原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。