我有兩個表刪除unforgeted記錄
CREATE TABLE `server` (
`server_id` int(3) NOT NULL AUTO_INCREMENT,
`server_name` varchar(15),
`server_alias` varchar(50),
`server_status` tinyint(1) DEFAULT '0',
`server_join` tinyint(1) DEFAULT '1',
`server_number_member` int(5),
PRIMARY KEY (`server_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `member` (
`member_id` int(11) NOT NULL AUTO_INCREMENT,
`member_server` int(3) DEFAULT NULL COMMENT 'Id server',
`member_name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Tên của member',
PRIMARY KEY (`member_id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
的創建表VIEW
獲取列表服務器
CREATE VIEW `server_client` AS
SELECT
`s`.`server_id` AS `server_id`,
`s`.`server_name` AS `server_name`,
`s`.`server_alias` AS `server_alias`,
IF (`s`.`server_join` = 1, (COUNT(`m`.`member_id`)/`s`.`server_number_member` * 100) DIV 1, 100) AS `server_full`
FROM (`server` `s`
LEFT JOIN `member` `m`
ON ((`m`.`member_server` = `s`.`server_id`)))
WHERE `s`.`server_status` = 1
現在,server
表有1次的記錄:
-------------------------------------------------------------------------------------------
|server_id|server_name|server_alias |server_status|server_join|server_number_member|
|-----------------------------------------------------------------------------------------|
| 1 | SV 01 | http://example.com/ | 0 | 0 | 10 |
-------------------------------------------------------------------------------------------
在member
表
------------------------------------------
| member_id | member_server | member_name|
|----------------------------------------|
| 1 | 1 | aaa |
|----------------------------------------|
| 2 | 1 | bbb |
|----------------------------------------|
| 3 | 1 | ccc |
------------------------------------------
結果在server_client
表
--------------------------------------------------------
| server_id | server_name | server_alias | server_full |
|------------------------------------------------------|
| NULL | NULL | NULL | 100 |
--------------------------------------------------------
server_full
用於計算已經在服務器
我想刪除記錄NULL在server_client
表成員的數量的百分比 怎麼做
謝謝
「左連接」是否應該使用正確的連接? –
使用「group by's'.'server_id'」 –
@AkshayH那對我來說 –