<pre class="sql" name="code">INSERT INTO `mail_table` (title,sender_id,sender_name,recver_id,recver_name,body,item_id,Item_num,expire,create_time)
SELECT '补偿','0','',id,name,'批量邮件','7675','1',UNIX_TIMESTAMP(NOW()), FROM
#group by 唯一账号 保存到tb表
(SELECT * FROM `char_table` WHERE LEVEL >= 20 GROUP BY account_id) AS tb
通过别的表获取id发送邮件
mysql> select * from t1;
+---+---+
| i | j |
+---+---+
| 1 | 1 |
| 2 | 2 |
+---+---+
mysql> select * from t2;
| k | j |
+---+---+
| 3 | 1 |
| 2 | 2 |
+---+---+
join on 加入表(扩充列) on作为id关联
mysql> select * from t2 join t1 on (t1.j = t2.j);
;
+---+---+---+---+
| k | j | i | j |
+---+---+---+---+
| 3 | 1 | 1 | 1 |
| 2 | 2 | 2 | 2 |
+---+---+---+---+
union和union all联合(扩充行)
需要保证列数相同,union会把重复行过滤,union all会显示全部。
select * from t1 union (select * from t2);
+---+---+
| i | j |
+---+---+
| 1 | 1 |
| 2 | 2 |
| 3 | 1 |
+---+---+