[英]How to create a table where one column contains a same value for all rows with different id?(See Layout for clarity)
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 ). 看起来您有两个实体(在实体关系数据建模的术语中)。
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.