1

我的问题主要是我不确定如何在搜索中说出我需要的内容。

mysql> SELECT * FROM `accounts`;
+----+--------+---------+----------+
| id | status | oplevel | username |
+----+--------+---------+----------+
| 10 |      1 |       0 | root     |
| 11 |      1 |       1 | Xylex    |
| 12 |      1 |      16 | Anubis   |
| 13 |      0 |      16 | Kami     |
| 14 |      1 |      16 | Zorn     |
+----+--------+---------+----------+


mysql> SELECT * FROM `networks`;
+-----------+-----------+-------------+-----------------+
| networkid | accountid | networkname | serveraddress   |
+-----------+-----------+-------------+-----------------+
|         1 |        10 | Fakenet     | irc.fakenet.org |
|         2 |        10 | Undernet    | irc.under.net   |
|         3 |        12 | Takenet     | irc.takenet.com |
|         4 |        13 | Examplenet  | irc.example.org |
+-----------+-----------+-------------+-----------------+

我有这个帐户表和这个网络表我需要一个查询来返回 IRC 网络的地址,只有当相应的帐户 ID 状态列是 1(启用)

我一直在寻找几个小时。做什么?

4

3 回答 3

0

我已更新查询以放置帐户 ID。

select acc.id, acc.username, nw.serveraddress from accounts acc join networks nw on acc.id = nw.accountid where acc.status == 1 and acc.id=XXX
于 2013-02-03T02:27:47.847 回答
0
select serveraddress from networks, accounts where networks.accountid = accounts.id and accounts.satus=1;

是你要找的吗?

于 2013-02-03T02:28:29.390 回答
0

对我来说看起来很简单:

select serveraddress from accounts join networks on id=accountid and id=YOUR_ACCOUNT_ID_HERE

或者

select serveraddress from networks where accountid=YOUR_ID and exists(select * from accounts where id=accountid and status)

很多方法可以解决这个问题..

于 2013-02-03T02:32:53.937 回答