MSSQL DISTINCT多个字段会引发奇怪的结果 [英] MSSQL DISTINCT multiple fields throws up odd results

查看:125
本文介绍了MSSQL DISTINCT多个字段会引发奇怪的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个动态查询,从我的数据库中提取工作簿,表结构如下。


表:curricworkbooks

列:ID,curric,评估,主题,工作簿,文件名


示例数据

I.m creating a dynamic query to pull out workbooks from my database the table structure is below.

Table: curricworkbooks
Columns: ID, curric, assessment, topic, workbook, filename

Example data

展开 | 选择 | 换行 | 行号

推荐答案

请您发布以下内容以供参考:


1.示例数据

2.查询的输出数据

3.您需要的示例输出
Could you please post the following for reference:

1. Sample data
2. The output data of your query
3. The sample output that you require



您能否发布以下内容作为参考:


1.样本数据

2.您的输出数据查询

3.您需要的样本输出
Could you please post the following for reference:

1. Sample data
2. The output data of your query
3. The sample output that you require



表数据(缩小至仅1评估)

> http://www.bksb.co.uk/bksb /data/tabledata.php


查询1
http://www.bksb.co.uk/bksb/data/query1.php


查询2
http://www.bksb.co .uk / bksb / data / query2.php


我注意到Microsoft SQL studio会自动从DISTINCT(文件名)中取走括号这是正常的吗?因为这会选择不同的东西,这意味着ID永远不会相同所以相同。


我想我有点回答我自己的问题,但有什么方法可以选择只有1个不同的价值?我使用MySQL并且我会使用unique(文件名),即使mssql管理器突出显示它作为内置函数它返回说它不是函数。


问候

Liam

Table data (narrowed down to only 1 assessment)

http://www.bksb.co.uk/bksb/data/tabledata.php

Query 1
http://www.bksb.co.uk/bksb/data/query1.php

Query 2
http://www.bksb.co.uk/bksb/data/query2.php

I have noticed that Microsoft SQL studio automatically take away my brackets from DISTINCT(filename) Is this normal? As this would select distinct everything which means ID is never the same so all the same.

I think I?ve kind of answered my own question but is there any way around this to select by just 1 distinct value? I?m use to MySQL and I would use unique(filename) even although mssql manager highlights this as a built in function it returns saying it?s not a function.

Regards
Liam


我检查了示例数据,我发现同一工作簿的ID不同。因此,您的查询工作正常,因为当您说明显时,它会获得不同的记录,因为ID对于同一工作簿的每个记录都不同。现在,当您说您只需要一个记录时,每个记录都应该是工作簿,那么ID值应该是多少。


例如:对于工作簿= 2,ID为36,37,38,39,那么您要显示哪个值?如果全部四个,那么工作簿和文件名将重复所有记录。
I checked the sample data and I see that the ID is different for the same workbook. So your query is working perfectly since when you say distinct, it is getting distinct records because ID is different for each record of same workbook. Now when you say you want one record only each for workbook, then what should be the ID value.

For Eg: For workbook = 2, the ID are 36,37,38,39, so which value you want to display? If all the four, then the workbook and filename will repeat for all the records.


这篇关于MSSQL DISTINCT多个字段会引发奇怪的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆