如何将值列表添加到MySQL列中的列中?

时间:2017-12-20 10:19:18

标签: mysql sql

我有一个名为books的表和一个名为price的列。如何更新该列中的所有值?以下是我写的查询。

INSERT INTO `books`(`price`)
VALUES (176.00,
        337.00,
        234.00,
        180.00,
        135.00,
        72.00,
        72.00,
        81.00,
        135.00,
        113.00,
        162.00);

目前这是y表的外观。

| Book ID | Price |
|---------|-------|
| a       |       |
| b       |       |
| c       |       |
| d       |       |

这就是我想要的样子。

| Book ID | Price |
|---------|-------|
| a       | 12    |
| b       | 13    |
| c       | 14    |
| d       | 15    |

有人可以建议我应该如何修改查询吗?我也可以删除现有列并创建一个新列。

2 个答案:

答案 0 :(得分:1)

你可以使用它。

File

如果要更新,还需要源数据的id值。如果你有id也可以使用这种方法。

INSERT INTO `books`(`price`) VALUES (176.00), 
(337.00), (234.00), (180.00), (135.00), (72.00), (72.00), (81.00), (135.00), (113.00), (162.00);

答案 1 :(得分:1)

您可以针对您的问题尝试此解决方案:

表格结构:

package com.jerry.configuration;

import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class SpringAmqpConfiguration {

    protected final String helloWorldQueueName = "hello.world.queue";

    @Bean
    public ConnectionFactory connectionFactory() {
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");
        return connectionFactory;
    }

    @Bean
    public AmqpAdmin amqpAdmin() {
        return new RabbitAdmin(connectionFactory());
    }

    @Bean
    public RabbitTemplate rabbitTemplate() {
        RabbitTemplate template = new RabbitTemplate(connectionFactory());
        //The routing key is set to the name of the queue by the broker for the default exchange.
        template.setRoutingKey(this.helloWorldQueueName);
        //Where we will synchronously receive messages from
        template.setQueue(this.helloWorldQueueName);
        return template;
    }

    @Bean
    // Every queue is bound to the default direct exchange
    public Queue helloWorldQueue() {
        return new Queue(this.helloWorldQueueName);
    }

    @Bean 
    public Binding binding() {
        return declare(new Binding(helloWorldQueue(), defaultDirectExchange()));
    }

    //https://docs.spring.io/spring-amqp/docs/1.5.0.BUILD-SNAPSHOT/reference/html/_reference.html#async-annotation-driven

    @Bean
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        factory.setConcurrentConsumers(3);
        //If you want a fixed number of consumers, omit the max.
        factory.setMaxConcurrentConsumers(10);
        //Set message listener : container.setMessageListener(this.myFirstListener);
        return factory;
    }


    /**
    * Listener Bean
    * Threadpool 
    *     
    <bean id="messageListener" class="com.spring.rabbitmq.service.MessageListenerService" />

    <rabbit:listener-container connection-factory="connectionFactory">
        <rabbit:listener ref="messageListener" queues="my.first.queue" />
    </rabbit:listener-container>

    */


}

您也可以参考sqlfiddle

我希望它会有所帮助。