问答详情
源自:2-1 MySQL-行转列场景介绍

实际例子的代码

怎么没有学习课件

提问者:tongwust 2015-12-05 23:07

个回答

  • 不爱学习的大猫
    2015-12-15 15:54:56
    已采纳

    你跟着视频,自己动手去敲,重在理解

  • 超级大傻花_biu_biu
    2019-08-22 09:43:50

    自己建的,和老师有一丢丢不一样,数据也插入了,自取,可参考。

    -- 师徒四人

    CREATE TABLE user1(

    id TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,

    user_name VARCHAR(20),

    user_over VARCHAR(20),

    mobile VARCHAR(20)

    )

    INSERT INTO user1 VALUES(NULL,'唐僧','功德佛',NULL);

    INSERT INTO user1 VALUES(NULL,'猪八戒','净坛使者',NULL);

    INSERT INTO user1 VALUES(NULL,'孙悟空','斗战胜佛',NULL);

    INSERT INTO user1 VALUES(NULL,'沙僧','金身罗汉',NULL);


    SELECT * FROM user1;


    -- 悟空结拜兄弟

    CREATE TABLE user2(

    id TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,

    user_name VARCHAR(20),

    user_over VARCHAR(20)

    );

    INSERT INTO user2 VALUES(NULL,'孙悟空','成佛');

    INSERT INTO user2 VALUES(NULL,'牛魔王','被降伏');

    INSERT INTO user2 VALUES(NULL,'蛟魔王','被降伏');

    INSERT INTO user2 VALUES(NULL,'鹏魔王','被降伏');

    INSERT INTO user2 VALUES(NULL,'狮驼王','被降伏');


    SELECT * FROM user2;


    -- 打怪记录表

    CREATE TABLE user_kills(

    id TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,

    user_id TINYINT UNSIGNED,

    timestr DATETIME,

    kills SMALLINT UNSIGNED

    )

    INSERT INTO user_kills VALUES(NULL,2,'2013-01-10',10);

    INSERT INTO user_kills VALUES(NULL,2,'2013-02-01',2);

    INSERT INTO user_kills VALUES(NULL,2,'2013-02-05',12);

    INSERT INTO user_kills VALUES(NULL,4,'2013-01-10',3);

    INSERT INTO user_kills VALUES(NULL,4,'2013-02-11',5);

    INSERT INTO user_kills VALUES(NULL,4,'2013-02-06',1);

    INSERT INTO user_kills VALUES(NULL,3,'2013-01-11',20);

    INSERT INTO user_kills VALUES(NULL,3,'2013-02-12',10);

    INSERT INTO user_kills VALUES(NULL,3,'2013-02-07',17);


    SELECT * FROM user_kills;


  • 鸟笨
    2016-03-09 11:22:58

    自己建表也不麻烦

  • tongwust
    2015-12-19 18:26:29

    最基本的原始表都没有 模拟起来都很麻烦,你也要人性化一点吧