gpt4 book ai didi

mysql - sql 从两个不同的表中选择查询 WHERE active=1

转载 作者:行者123 更新时间:2023-11-29 11:37:24 25 4
gpt4 key购买 nike

我尝试从两个不同的表中选择所有列,其中 active = 1

我有 2 个表 table_protable_basic

sql:"select * from table_basic,table.name";

and 2 condition:

  1. WHERE active = 1
  2. WHERE table_pro.id = table_basic.name.id

如何正确制作

这是表_pro

+----+--------+---------+-----------+
| id | people | rooms | active |
+----+--------+---------+-----------+
| 1 | 5 | 10 | 0 |
| 2 | 12 | 17 | 0 |
| 3 | 21 | 38 | 1 |
+----+--------+---------+-----------+

这是table_basic

+---------+-------+---------+------------+----------+
| name_id | name | balance | title | time |
+---------+-------+---------+------------+----------+
| 1 |shop | 100 | failed | 15:10:20 |
| 2 |factory| 75 | error | 15:10:20 |
| 3 |studio | 25 | timed_out | 15:10:20 |
+---------+-------+---------+------------+----------+

我希望此输出结果仅包含状态为 active = 1 的行(来自所有列)

+-----+-------+----- --+--------+-------+----------+---------+--------+
| id | people| rooms | name |balance| title | time | active |
+-----+-------+--------+--------+-------+----------+---------+--------+
| 3 | 21 | 38 | studio |25 | timed_out| 15:10:20| 1 |
+-----+-------+--------+--------+-------+----------+---------+--------+

谢谢

最佳答案

SELECT A.id, A.people, A.rooms, B.name, B.balance, B.title, B.time, A.active 
FROM
table_pro AS A
JOIN
table_basic AS B
ON
A.id = B.name_id
WHERE
A.id = 3

关于mysql - sql 从两个不同的表中选择查询 WHERE active=1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36358606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com