在我的Microsoft Access 365的产品注册数据库中,我有表tbl_main_new_注册和tbl_supp_composations.

我正在try 创建一个SQL查询,以便它可以在一行中显示BRAND_NAME(此字段在表1中)及其所有Active_Components(表2中的此字段).然而,我却想不通.目前,我的疑问是:

SELECT tbl_main_new_registration.[brand_name], tbl_supp_compositions.active_ingredient, tbl_supp_compositions.strength
FROM tbl_main_new_registration 
INNER JOIN tbl_supp_compositions 
ON tbl_main_new_registration.new_reg_id = tbl_supp_compositions.brand_name;

并得出了以下结果:

enter image description here

我希望通过以下方式实现这一目标:

enter image description here

我已经try 了一些在线解决方案,即http://allenbrowne.com/func-concat.html,但我无法理解和应用它.此外,我试图应用Stackoverflow中的一些答案,但我认为我无法完全理解它.

推荐答案

使用我的DJoin函数的这个查询将执行以下操作:

SELECT 
    tbl_main_new_registrations.Id, 
    tbl_main_new_registrations.[Brand Name], 
    DJoin("[active_ingredient] & ': ' & [strength]","[tbl_supp_compositions]","[BrandNameId] = " & [Id] & "",": ") AS active_ingredients
FROM 
    tbl_main_new_registrations
GROUP BY 
    tbl_main_new_registrations.Id, 
    tbl_main_new_registrations.[Brand Name], 
    DJoin("[active_ingredient] & ': ' & [strength]","[tbl_supp_compositions]","[BrandNameId] = " & [Id] & "",": ")
ORDER BY 
    tbl_main_new_registrations.Id;

enter image description here

Sql相关问答推荐

如何重用表值用户定义函数调用的结果?

判断Pyspark生成的SQL查询

Group By子句返回太多行

为什么在这种情况下我不能使用LAG函数?

基于多参数的SQL Server条件过滤

具有多个条件的SQL否定

SQL到Snowflake-转换嵌套的SELECT(值

如何使用聚合连接两个表

根据日期 Select ID 的上一条记录

当 ansible 变量未定义或为空时,跳过 sql.j2 模板中的 DELETE FROM 查询

仅当 SQL Server 中的表为开时,才在存储过程中使用更改跟踪

在 SQL Server 中查找重复项

Spark / Hive:如何获取列中正值的百分比?

使用 SAVE TRANSACTION 时 BEGIN 和 COMMIT 语句的数量不匹配

根据开始/结束标记将 GROUP_ID 分配给行

BigQuery - 将 TIMESTAMP 转换为 HH:MM:SS,然后识别 TIME_DIFF

包含多行的 SQL 查询

Postgres 窗口函数未按预期工作

使用 SQL 表中的连接列删除重复记录

从多个连接返回 1 行到同一个表 - SQL Server