考虑以下mysql查询:
create temporary table t (a tinyint); insert into t values (1),(1),(2);
select * from t;
-- +------+
-- | a |
-- +------+
-- | 1 |
-- | 1 |
-- | 2 |
-- +------+
select c,count(*) from (select a,count(*) c from t group by a) u
group by c;
-- +---+----------+
-- | c | coun
在这种情况下,我可以从MYSQL数据库中的多个表中进行选择。在任何给定的时间,我只需要访问一个表。
我可以将表的名称放在一个变量中,然后在查询中设置它吗?这样当我想要更改表时,我只需要更新一个变量?
我是这样想的:
而不是:
$order = "SELECT * FROM 2FieldForm ORDER BY ID";
执行以下操作:
$table = mysql_select_table("2FieldForm");
$order = "SELECT * FROM $table ORDER BY ID";
现在我甚
file = open("BasicTextFile.txt", "w")
query = "SELECT name, amount, description FROM customers_payments7777 GROUP BY customer_VAT"
mycursor.execute(query)
for row in mycursor:
file.write(f"{row[0]}\t{row[1]}\t\t{row[2]}")
file.write("\n")
file.close(