本文介绍了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评估)

>


查询1



查询2



我注意到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



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

10-22 22:22