问题描述
我在创建查询时需要帮助.我有客户端表,其中包含唯一的客户端信息 - 由其唯一的 ClientID 标识.我还有一个 Client_UserDefinedFields 表,其中包含客户端的自定义数据值.它们通过 ClientID 链接,并且在这个 Client_UserDefinedFields 表中可能有许多针对 ClientID 的记录.
I need assistance in creating a query. I have Client table that has unique client info - identified by their unique ClientID. I also have a Client_UserDefinedFields table that contains values of custom data for clients. They are linked via the ClientID and there may be many records for a ClientID in this Client_UserDefinedFields table.
我的情况是有 3 个自定义数据字段,我需要知道给定客户端的值(如我的 CASE 语句所示).我当前的查询将客户端带回 3 次(每个值一行),我只想看到客户端一次(一行)并将这些值显示为列.不确定这是否可能或如何做到这一点.此外,当我尝试在我的选择中使用 CASE 语句时,我无法使用 AS 'fieldname' 来识别它 - 因为它在 AS 关键字上给了我一个错误.
My situation is that there are 3 custom data fields that I need to know the values for a given client (as shown by my CASE statement). My current query is bringing back the client 3 times (a row for each value) and I want to only see the client once (one row) and have these values shown as columns. Not sure if this is possible or how to that. Furthermore, when I tried using a CASE statement in my select, I cannot use AS 'fieldname' to identify it - since it's giving me an error on the AS keyword.
我当前的 SQL SELECT 语句示例
An example of my current SQL SELECT statement
同样,我的问题是,如果 Client_UserDefinedFields 表中有多个条目,我不想多次带回同一个客户端.我想把它放在一行中,每个状态"字段都正确填充为一列.我该怎么做呢?这是我当前输出的示例:
Again, my issue is that I don't want to bring back the same client multiple times if they had more than one entry in the Client_UserDefinedFields table. I'd like to bring this in one row with each "Status" field correctly populated as a columns. How do I do this? Here's a sample of my current output:
最终只想看到包含所有值的一条记录
Ultimately would like to see just the one record with all the values
示例非常有用,因为我不是 SQL 专家.谢谢!
Examples are very helpful as I'm not a SQL guru. Thank you!
推荐答案
这篇关于查询以在列而不是行中返回记录值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!