Q(FirstAuthor__isnull=not achievement__FirstAuthor)
时间: 2023-07-21 11:53:59 浏览: 80
这看起来像是一个Django QuerySet语句,它的作用是从数据库中过滤出满足以下条件的记录:
1. achievement__FirstAuthor不为空,即achievement表中的FirstAuthor字段不为空
2. 如果FirstAuthor__isnull为False,则查询结果中必须包含achievement表中的FirstAuthor字段
简单来说,这个查询语句的目的是找到符合条件的achievement记录中的FirstAuthor字段不为空的记录。
相关问题
为什么下面的sql语句会输出重复的结果:SELECT tp.parent_production_orders AS parent_production_orders, tp.production_orders AS production_orders, tp.work_order AS work_order, tp.contract AS contract, tp.sbbh AS sbbh, tp.batch_num AS batch_num, tp.product_code AS product_code, tp.product_number AS product_number, tp.product_name AS product_name, to_char( middle.create_date, 'yyyy-mm-dd' ) AS issued_date, to_char( to_timestamp( tp.delivery_time / 1000 ), 'yyyy-mm-dd' ) AS delivery_time, middle.line_code AS work_area_code, middle.line_name AS work_area_name, tp.workorder_number AS workorder_number, tp.complete_number AS complete_number, tp.part_unit AS part_unit, middle.work_time_type AS work_time_type, middle.process_time AS process_time, CASE WHEN sc.totalSubmitHours IS NULL THEN 0 ELSE sc.totalSubmitHours END AS submit_work_hours, CASE WHEN middle.process_time > 0 AND sc.totalSubmitHours IS NOT NULL THEN round( ( sc.totalSubmitHours / middle.process_time ), 2 ) * 100 ELSE 0 END plan_achievement_rate, CASE WHEN sc.totalSubmitHours IS NULL THEN 0 ELSE round( CAST ( sc.totalSubmitHours AS NUMERIC ) / CAST ( 60 AS NUMERIC ), 1 ) END AS submit_work_hours_h, round( CAST ( middle.process_time AS NUMERIC ) / CAST ( 60 AS NUMERIC ), 1 ) AS process_time_h, pinfo.material_channel AS material_channel FROM hm_model_work_order_report_middle middle LEFT JOIN hm_model_trc_plan tp ON middle.work_order = tp.work_order LEFT JOIN ( SELECT oro.work_order AS orderNo, oro.work_area_code AS lineCode, SUM ( submit_work_hours ) AS totalSubmitHours, '自制' AS workHourType FROM hm_model_trc_order_report_operation_u orou LEFT JOIN hm_model_trc_order_report_operation oro ON orou.work_order_process_id = oro.ID WHERE orou.work_order_process_id IS NOT NULL AND oro.work_area_code IS NOT NULL GROUP BY oro.work_order, oro.work_area_code UNION all SELECT ohs.work_order_no AS orderNo, ohs.line_code AS lineCode, SUM ( receiving_hour ) AS totalSubmitHours, '外委' AS workHourType FROM hm_model_outsourcing_hour_statistics ohs GROUP BY ohs.work_order_no, ohs.line_code ) sc ON middle.work_order = sc.orderNo AND middle.line_code = sc.lineCode AND middle.work_time_type = sc.workHourType LEFT JOIN hm_model_part_info AS pinfo ON tp.product_number = pinfo.part_code WHERE middle.process_time > 0 AND tp.delivery_time IS NOT NULL AND tp.production_orders LIKE'FJ2023051100286' ORDER BY to_char( to_timestamp( tp.delivery_time / 1000 ), 'yyyy-mm-dd' ) DESC, tp.parent_production_orders DESC, tp.node_level ASC
可能是因为查询结果中有多个相同的记录,即存在多个记录的各个字段的值都相同,因此会出现重复的结果。可以使用 DISTINCT 关键字去除重复的记录。例如:SELECT DISTINCT tp.parent_production_orders AS parent_production_orders, tp.production_orders AS production_orders, ... (省略后面的 SQL 语句)。另外,还可以检查查询条件是否合理,是否需要增加更多的条件来过滤数据。
创建学生成绩(db_student_achievement)数据库,在数据库中创建t_student、t_course、t_score、t_teacher四张数据表。 (1)具体结构如下 : ① 建库db_student_achievement ② 建表t_student
好的,你的问题是如何创建db_student_achievement数据库和t_student表。以下是SQL语句:
创建db_student_achievement数据库:
```
CREATE DATABASE db_student_achievement;
```
创建t_student表:
```
CREATE TABLE t_student (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
sex ENUM('男','女') NOT NULL,
age INT NOT NULL,
class VARCHAR(50) NOT NULL
);
```
t_student表包含以下字段:
- id:学生ID,自增长整数类型,主键。
- name:学生姓名,字符串类型,不能为空。
- sex:学生性别,枚举类型,只能为‘男’或‘女’。
- age:学生年龄,整数类型,不能为空。
- class:所在班级,字符串类型,不能为空。
注意:为了保证数据的准确性和完整性,还需要对t_student表进行其他约束和设定,如外键、索引、默认值、唯一性等。但这些约束和设定的具体情况需要根据实际需求来确定,这里就不一一列举了。
阅读全文