如何更新仅显示一次的列中的值?

时间:2018-05-23 14:19:02

标签: sql sqlite

如何更新仅在项目列中出现一次的项目的ID值?

表1

id | item | price
-------------
10 | pen  | 10  
20 | pen  | 10   
30 | pen  | 10
30 | copy | 10
10 | book | 10
10 | ball | 10

3 个答案:

答案 0 :(得分:2)

update table set 
id = <whatever>
where
item in (select item from table group by item having count(*)=1)

答案 1 :(得分:0)

您可以使用not exists

update t 
set t.id = <whatever>
where not exists (select 1 from table where item = t.item and id <> t.id);

答案 2 :(得分:-1)

试试这个

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section>

  <div class="grid_home">

    <div class="grid_home_inside displayed" style="background: url(https://upload.wikimedia.org/wikipedia/commons/1/16/Appearance_of_sky_for_weather_forecast%2C_Dhaka%2C_Bangladesh.JPG) no-repeat center center;background-size:cover;"></div>

    <div class="grid_home_inside" style="background: url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR0A3u74LuIJ6OgDXWY4yWW_4F9bXs_VHTKfxdn-vhjWTlBnz-a) no-repeat center center;background-size:cover;"></div>

    <div class="grid_home_inside" style="background: url(http://www.slate.com/content/dam/slate/blogs/bad_astronomy/2015/10/151027_BA_blue-sky.jpg.CROP.promo-xlarge2.jpg) no-repeat center center;background-size:cover;"></div>

  </div>

</section>