如何从 SQL Server 中的值列表中进行选择

2023-10-08数据库问题
2

本文介绍了如何从 SQL Server 中的值列表中进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个非常简单的问题,我无法解决.我需要做这样的事情:

I have very simple problem that I can't solve. I need to do something like this:

select distinct * from (1, 1, 1, 2, 5, 1, 6).

有人可以帮忙吗??

编辑

数据来自我们的一位客户的文本文件.它完全没有格式化(它是一行很长的文本),但在 Excel 中可能会这样做.但这对我来说并不实用,因为我需要在我的 sql 查询中使用这些值.每次需要运行查询时都这样做很不方便.

The data comes as a text file from one of our clients. It's totally unformatted (it's a single, very long line of text), but it may be possible to do so in Excel. But it's not practical for me, because I will need to use these values in my sql query. It's not convenient to do so every time I need to run a query.

推荐答案

获取一长串逗号分隔文本的不同值的最简单方法是使用 find an replace with UNION 以获得不同的值.

Simplest way to get the distinct values of a long list of comma delimited text would be to use a find an replace with UNION to get the distinct values.

SELECT 1
UNION SELECT 1
UNION SELECT 1
UNION SELECT 2
UNION SELECT 5
UNION SELECT 1
UNION SELECT 6

应用于您的逗号分隔文本的长行

Applied to your long line of comma delimited text

  • 找到并用 UNION SELECT
  • 替换每个逗号
  • 在语句前添加SELECT

您现在应该有一个有效的查询

You now should have a working query

这篇关于如何从 SQL Server 中的值列表中进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

按天分组的 SQL 查询
SQL query to group by day(按天分组的 SQL 查询)...
2024-04-16 数据库问题
77

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

在 Group By 查询中包含缺失的月份
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)...
2024-04-16 数据库问题
12

sql group by 与不同
sql group by versus distinct(sql group by 与不同)...
2024-04-16 数据库问题
37

如何在SQL中返回每个组的增量组号
How to return a incremental group number per group in SQL(如何在SQL中返回每个组的增量组号)...
2024-04-16 数据库问题
8

统计分组返回的记录数
Count number of records returned by group by(统计分组返回的记录数)...
2024-04-16 数据库问题
10