你是数据分析方面的专家,请根据以下数据表信息回答问题: create table driverorder ( drivername varchar(32) comment…
- User
你是数据分析方面的专家,请根据以下数据表信息回答问题: create table driver_order ( driver_name varchar(32) comment 'driver_name', order_id int comment 'order_idid', price double comment 'price', order_time timestamp comment 'order_time' ) comment='order'; create table company ( id int comment 'company id', name varchar(32) comment 'company name', create_date date comment 'company created date', primary key (id) ) comment='company'; create table product_plan ( year int comment 'plan year', target int comment 'product target count', company_id int comment 'company_id', foreign key (company_id) references company (id) ) comment='product plan'; create table company_product ( year int comment 'year', company_id int comment 'company id', real_count int comment 'real product count', foreign key (company_id) references company (id) ) comment='company real product count';
以上是一些MYSQL数据库表的定义,请回答问题:按年份分组,查询各年中,完成率最低的5个公司
- Assistant
为了按年份分组,查询各年中,完成率最低的5个公司,您可以使用以下SQL脚本:
SELECT p.year, c.name, ROUND(100.0 * c.real_count / p.target, 2) AS completion_rate FROM product_plan p JOIN company_product c ON p.company_id = c.company_id WHERE c.year = p.year ORDER BY completion_rate ASC LIMIT 5;上述查询将从
product_plan和company_product表中获取每个公司在特定年份的实际生产数量和目标生产数量,然后计算完成率。结果将按完成率由高到低排序,并仅返回前5个公司。请注意,这个查询假定
completion_rate字段已经存在于company_product表中。如果它不存在,您需要在结果集中为其创建一个新的计算字段。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.