以下數據表 表名 字段
character_items id character_teleport id character_warehouse id character_elf_warehouse id clan_data clan_id clan_warehouse id條件:給與一個 int 參數 在以上表中的id 字段中 都找不到! 完成時間 3:30 老闆要求的:小弟先PO文求助,怕完成不了!回去研究去了,請各位大蝦幫忙!
character_items id character_teleport id character_warehouse id character_elf_warehouse id clan_data clan_id clan_warehouse id條件:給與一個 int 參數 在以上表中的id 字段中 都找不到! 完成時間 3:30 老闆要求的:小弟先PO文求助,怕完成不了!回去研究去了,請各位大蝦幫忙!
union all
select id from character_teleport
union all
......这样把ID全部串起来,放到一起,你爱怎么查就可以怎么查。
大大我錯了,這種語句不行,我講明一下 在以上的那些表中 ,隨機產生一個大於 2E的int類型的整數,但是又不能在上述所有表中的id字段存在,全部用SQL 語句來執行.就是說: 產生的隨機數,不能在上述表中的 id 字段存在,有就重新隨機,一直到不存在的,返回一個值出來!
insert into tmp values (i)写入一个临时表
查询就很简单了
select tmp.id from tmp where not exists(select 1 from (select id from character_items
union all
select id from character_teleport
union all
....
) b where tmp.id <> b.id ) limit 1;TMP表有N多的整形数据,再去比较,取出一个。
union all
select id from character_teleport
union all
....
) b ;这样把所有ID集合起来,取最大值,然后+1,肯定就没问题了。
mysql> select * from a1;
+----+-------+
| id | title |
+----+-------+
| 1 | 1 |
| 10 | 1 |
| 20 | 2 |
+----+-------+
3 rows in set (0.00 sec)mysql> select id+1 from a1 a where not exists(select id from a1 b where a.id>b.i
d);
+------+
| id+1 |
+------+
| 2 |
+------+
1 row in set (0.00 sec)mysql>是要求这样的结果么?