基于SQL中的多个值选择列 [英] selecting a column based on multiple values in SQL

查看:80
本文介绍了基于SQL中的多个值选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..

下午好..

在我的表中,表中有两列名为batchname,process.
bachname包含1000个文件名,process包含文件是否已完成.

我的问题是,
我想根据1000个文件名选择处理列.
有人可以提供查询吗?如何传递1000个文件名以获取对应文件的处理列?

在此先感谢

Hello all..

Good afternun..

In my table I have two column in a table named as batchname,process.
bachname contains the 1000 filename,process contains whether the file is completed or not.

My problem is,
I want to select the process column based on 1000 file name.
can anybody provide the query for that?How to pass the 1000 file name to get a process column for the corresponding file?

thanks in advance

推荐答案

如果您知道文件名,可以尝试以下方法:

If you know the filenames, you can try something along the lines of:

SELECT process
FROM table_name
WHERE batchname IN ('batchname1', 'batchname2,', 'batchname3', 'batchname1000');



现在的问题是,您将不得不想出一种方法来动态地将它们放在WHERE子句中,编写1000个文件名会很无聊(更不用说明天它们可能是10,000个).



Now, the problem is that you''ll have to come up with a way to put those dynamically in the WHERE clause, writing 1000 file names would be painfully boring (not to mention the fact that they may be 10,000 tomorrow).


不确定我是否正确理解了您的问题,但是如果您在一行(和一列)中有多个批处理名称,然后在描述单个过程的列中有多个,应该改变桌子的设计.例如类似:
Not sure if I understood your question correctly, but if you have several batch names on a single row (and in a single column) and then a column describing a single process, I think you should change the design of your tables. For example to something like:
Process
- processid, primary key
- name
- status ...

Batch
- processid, foreign key to process
- name ...


如果表有1000行,并且需要1000个批处理名称的过程信息,则只需选择所有行.
否则,您可以使用"in"子句.尽管如果您输入1000个值,可能会造成混乱.
If your table has 1000 rows and you need process information of 1000 batchname, you can simply select all the rows.

Otherwise you could make use of "in" clause. Although this may get messy if you put 1000 values.


这篇关于基于SQL中的多个值选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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