简体   繁体   English

如何创建一个表,其中一列包含具有不同ID的所有行的相同值?(有关说明,请参见布局)

[英]How to create a table where one column contains a same value for all rows with different id?(See Layout for clarity)

该图显示了示例报告,为空

In this table score, start date , Completion Date will be same for all error code but will be taken as an input once in the beginning. 在此表得分中,所有错误代码的开始日期,完成日期均相同,但在开始时将被视为一次输入。

This is a guess because your question isn't very clear. 这是一个猜测,因为您的问题不是很清楚。 You are looking for a one-to-many pattern to hold this collection of data. 您正在寻找一对多模式来保存此数据集合。

It looks like you have two entities (in the parlance of entity-relationship data modeling ). 看起来您有两个实体(在实体关系数据建模的术语中)。

  1. Review 评论
  2. Review Error 审核错误

Review has a one-to-many relationship to Review Error: each review may have zero or more Review Errors associated with it. 评论与评论错误具有一对多的关系:每个评论可能具有零个或多个与之相关的评论错误。 You showed two in your image, but you should still use the one-to-many relationship. 您在图像中显示了两个,但仍应使用一对多关系。

Your Review entity turns into a table like this 您的评论实体变成了这样的表格

review:
   review_id    INT   PK
   type         1=Peer Review, 2= Internal Review
   score        FLOAT?  INT?
   start_date   TIMESTAMP
   end_date     TIMESTAMP

Your Review Error entity turns into a table like this 您的Review Error实体变成了这样的表格

review_error_id    INT PK
review_id          INT FK to review table
ordinal            INT   0,1,2 showing order of items in report
error              VARCHAR(255)  
description        VARCHAR(255)
quantity           INT? FLOAT?

Then to generate the report hinted at by your example table, you do 然后,要生成示例表提示的报告,您可以

 SELECT review.type,
        review_error.error,
        review_error.description,
        review_error.quantity
        review.score,
        review.start_date,
        review.end_date
   FROM review
   LEFT JOIN review_error ON review.review_id = review_error.review_id
  ORDER BY review.review_id
           review_error.ordinal

You use LEFT JOIN because ordinary JOIN will suppress review rows that have no matching review_error rows. 您可以使用LEFT JOIN因为普通JOIN将取消review有没有匹配行review_error行。

If you want the boxes and column headers shown in your image, you'll need to generate those with a client side program. 如果要在图像中显示框和列标题,则需要使用客户端程序生成它们。 For example, you can define borders around cells in HTML tables. 例如,您可以在HTML表格中的单元格周围定义边框。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 计算来自不同表的特定值的行,两个表都包含同一列? - count rows for particular value from different table both table contains one same column? 如何在第 4 列包含与另一个表相同的 ID 的表中显示 3 列中的所有数据? - How to display all data in 3 columns from a table where the 4th column contains the same ID as another table? 根据不同列的行之一上的值返回具有相同 id 的所有行 - Return all rows that have the same id based on a value on one of the rows of a different column 如何选择列包含ID的所有行? - How to select all rows where column contains ID? 如果某一列包含特定值,则选择具有相同ID的所有行 - Select all rows with same IDs if one column contains a particular value MySql获取id = xxx且id相同的行中其他表中的最新列大于一个的所有行 - MySql get all rows where id = xxx and where the newest column in other table in row with same id is greater than one 如何获取所有行,其中特定列=不同表中另一行的ID - how to get all rows where specific column = id of other row in different table Select 所有行在一列中包含相同的值 - Select all rows contains same value in a column Select 行,其中 ID 相同但名称在多个记录中包含不同数据 - Select rows where ID is same but Name contains different data in more than one record 如何 select 引用表中一个 ID 的所有实例是否至少包含来自不同列的另一个 ID 的一个实例? - How to select all instance of an ID from a reference table based on whether it contains at least one instance of another ID from a different column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM