我有一个表data
,其中有5列,即id
,genre
,actor
,actress
,price
。在表中,id
有多个条目。由于其中一些是空的,我最终希望每个id获得一行。
示例(仅重复2次)
id genre actor actress price
5 a NULL b1 NULL
5 a a1 NULL $5
要实现
id genre actor actress price
5 a a1 b1 $5
答案 0 :(得分:1)
您可以使用聚合。例如:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="container">
<div class="form-container">
<!-- image-container -->
<div class="image-container">
<div class="bordered-div">
</div>
</div>
<!-- image-container end -->
<div class="row no-gutters form-tab">
<div class="col-md-2 offset-md-3">
<h6 class="text-capitalize text-right">product details</h6>
</div>
<div class="col-md-2">
<h6 class="text-capitalize text-right">graphic assets</h6>
</div>
<div class="col-md-2">
<h6 class="text-capitalize text-right">categorization</h6>
</div>
</div>
<div class="form-input">
<!-- İnputs -->
</div>
</div>
</div>
这为每一列选择一个值。如果可以有多个值,可以将它们放在数组中:
select id, genre, max(actor), max(actress), max(price)
from t
group by id, genre;