coalesce(item1,item2,item3)
依次判断item值,返回第一个不为null的值,若全为null,则返回null;
依次判断item值,返回第一个不为null的值,若全为null,则返回null;
2016-08-09
create table tb_sequence(id int auto_increment not null ,primary key(id) );
insert into tb_sequence values(),(),(),(),(),(),(),(),(),(),(),(),();
insert into tb_sequence values(),(),(),(),(),(),(),(),(),(),(),(),();
2016-08-05
删除重复行,并保留id最大的:
DELETE a
FROM user1_test a JOIN
(SELECT user_name, COUNT(*), MAX(id) AS id FROM user1_test GROUP BY user_name HAVING COUNT(*)>1) b
ON a.user_name = b.user_name
WHERE a.id < b.id;
DELETE a
FROM user1_test a JOIN
(SELECT user_name, COUNT(*), MAX(id) AS id FROM user1_test GROUP BY user_name HAVING COUNT(*)>1) b
ON a.user_name = b.user_name
WHERE a.id < b.id;
2016-07-29
SELECT user_name, 'arms' AS equipment, arms FROM user1 a JOIN user1_equipment b ON a.id = b.user_id
UNION ALL
SELECT user_name, 'clothing' AS equipment, arms FROM user1 a JOIN user1_equipment b ON ...
UNION ALL
SELECT user_name, 'shoe' AS equipment, arms FROM user1 a JOIN user1_equipment b ON ...
UNION ALL
SELECT user_name, 'clothing' AS equipment, arms FROM user1 a JOIN user1_equipment b ON ...
UNION ALL
SELECT user_name, 'shoe' AS equipment, arms FROM user1 a JOIN user1_equipment b ON ...
2016-07-28
SELECT user_name, arms, clothing, shoe FROM user1 a JOIN user1_equipment b ON a.id = b.user_id;
2016-07-28
INSERT INTO user1_equipment VALUES (NULL, 3, '金箍棒', '梭子黄金甲', '藕丝步云履');
INSERT INTO user1_equipment VALUES (NULL, 2, '九齿钉耙', '僧衣', '僧鞋');
INSERT INTO user1_equipment VALUES (NULL, 4, '降妖宝杖', '僧衣', '僧鞋');
INSERT INTO user1_equipment VALUES (NULL, 1, '九环锡杖', '锦斓袈裟', '僧鞋');
INSERT INTO user1_equipment VALUES (NULL, 2, '九齿钉耙', '僧衣', '僧鞋');
INSERT INTO user1_equipment VALUES (NULL, 4, '降妖宝杖', '僧衣', '僧鞋');
INSERT INTO user1_equipment VALUES (NULL, 1, '九环锡杖', '锦斓袈裟', '僧鞋');
2016-07-28
CREATE TABLE user1_equipment (
id TINYINT UNSIGNED AUTO_INCREMENT NOT NULL,
user_id SMALLINT UNSIGNED,
arms VARCHAR(10) CHARACTER SET utf8 DEFAULT NULL,
clothing VARCHAR(10) CHARACTER SET utf8 DEFAULT NULL,
shoe VARCHAR(10) CHARACTER SET utf8 DEFAULT NULL,
PRIMARY KEY(id)
);
id TINYINT UNSIGNED AUTO_INCREMENT NOT NULL,
user_id SMALLINT UNSIGNED,
arms VARCHAR(10) CHARACTER SET utf8 DEFAULT NULL,
clothing VARCHAR(10) CHARACTER SET utf8 DEFAULT NULL,
shoe VARCHAR(10) CHARACTER SET utf8 DEFAULT NULL,
PRIMARY KEY(id)
);
2016-07-28