Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SQLAlchemy中的concat多列_Python_Mysql_Sql_Sqlalchemy - Fatal编程技术网

Python SQLAlchemy中的concat多列

Python SQLAlchemy中的concat多列,python,mysql,sql,sqlalchemy,Python,Mysql,Sql,Sqlalchemy,Have Account表,其中包含项目id、项目名称、文档计数、帐户名称。 一个帐户有多个项目。我想收集每个帐户的所有项目数据 数据库:AWS Aurora 型号: 以前,我必须只计算每个帐户的项目ID。我用了下列方法 table = Account column_name = project_id filters = Some condition columns_to_select = ["account_id", "account_name"] label = project_ids 以

Have Account表,其中包含项目id、项目名称、文档计数、帐户名称。 一个帐户有多个项目。我想收集每个帐户的所有项目数据

数据库:AWS Aurora 型号:

以前,我必须只计算每个帐户的项目ID。我用了下列方法

table = Account
column_name = project_id
filters = Some condition
columns_to_select = ["account_id", "account_name"]
label = project_ids
以下sqlalchemy代码(工作代码)

上述代码的输出:

[{'project_ids': '8882-4ba7-a86e-016d1d58bbc1', 'account_id': '2389-4ea7-9ff2-94fc15eaa981', 'account_name': 'ABC'}, {'project_ids': 'd081-4956-8604-365d6976a842,cu61-34556-76704-323fs6976a845', 'account_id': '9f7d-460f-9de1-800e457d91ef', 'account_name': 'XYZ'}]
现在我想要“项目名称”和结果中的文档计数。 我做不到

输入:

table = Account
column_names = project_id, project_name, document_count
filters = Some condition
columns_to_select = ["account_id", "account_name"]
label = collected_data
预期产出:

[
  {
    'collected_data': [('8882-4ba7-a86e-016d1d58bbc1', "project-001", 23)], 
    'account_id': '2389-4ea7-9ff2-94fc15eaa981', 'account_name': 'ABC'
  }, 
  {
    'collected_data': [('d081-4956-8604-365d6976a842, "project-002", 12), 
                       ('cu61-34556-76704-323fs6976a845', "project-003", 212)]
    'account_id': '9f7d-460f-9de1-800e457d91ef', 'account_name': 'XYZ'}
]

请让我知道有人可以在这方面帮助我。

您是在寻找SQL还是SQLAlchemy答案?我需要SQLAlchemy,但SQL查询也很好,我可以转换为SQLAlchemy@IljaEverilä:补充。在aws aurora数据库上工作,添加了模型模式和query@IljaEverilä:MySQL你在寻找SQL或SQLAlchemy答案吗?我需要SQLAlchemy,但SQL查询也很好,我可以转换为SQLAlchemy@IljaEverilä:补充。在aws aurora数据库上工作,添加了模型模式和query@IljaEverilä:MySQL
table = Account
column_names = project_id, project_name, document_count
filters = Some condition
columns_to_select = ["account_id", "account_name"]
label = collected_data
[
  {
    'collected_data': [('8882-4ba7-a86e-016d1d58bbc1', "project-001", 23)], 
    'account_id': '2389-4ea7-9ff2-94fc15eaa981', 'account_name': 'ABC'
  }, 
  {
    'collected_data': [('d081-4956-8604-365d6976a842, "project-002", 12), 
                       ('cu61-34556-76704-323fs6976a845', "project-003", 212)]
    'account_id': '9f7d-460f-9de1-800e457d91ef', 'account_name': 'XYZ'}
]