SQL查询 - 返回一个特定列 [英] SQL Query - Returning One Specific Column

查看:85
本文介绍了SQL查询 - 返回一个特定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我需要一些sql查询的帮助我正在尝试。

我有一张我从excel复制的表格。


目前我拥有的列是姓名,电话,W1,W2,W3,W4,W5,W6,W7。


这些W列在每个列中包含日期(作为字符串)。


我想要做的查询是为每个拥有09的人(即9月)选择名称和W单元格)在任何W列中。我可以使用以下代码执行此操作:


SELECT Adults.NAME,W1,W2,W3,W4,W5,W6,W7

FROM成人

WHERE(((Adults.W1)喜欢''* 09 / *''))或(((Adults.W2)喜欢''* 09 / *''))OR(( (Adults.W3)喜欢''* 09 / *''))或(((Adults.W4)喜欢''* 09 / *''))或(((Adults.W5)喜欢''* 09 / * ''))或(((Adults.W6)喜欢''* 09 / *''))或(((Adults.W7)喜欢''* 09 / *''));

但是,我希望我的输出显示的只是九月的日期。现在它显示了与该人相关的所有其他日期。我知道我得到了所有这些额外的输出,因为我的SELECT行声明W1 ... W7 - 但我不知道如何更改我的代码只产生9月的东西。


我知道这听起来有点令人困惑,但任何帮助都会非常感激。


谢谢

解决方案

SELECT NAME,W1, W2,W3,W4,W5,W6,W7

来自成人

WHERE((月(CDate(W1))= 9)OR(月(CDate(W2)) )= 9)

OR(月(CDate(W3))= 9)或(月(CDate(W4))= 9)

OR(月(CDate( W5))= 9)OR(月(CDate(W6))= 9)

OR(月(CDate(W7))= 9));


谢谢你...但是,我没有专门使用约会。


让我告诉你一个我的意思的例子 - 如果我能,请告诉我通过电子邮件向您发送样本文件,以便您更容易理解我的要求:-)


W列包含以下文本:

D09 / 17或G03 / 23 - 字母p后退是我需要的一些代码,我的coumns。因此,这就是为什么我在我的查询中使用了术语Like,以便我可以选择其他具有09的列。



hi ,谢谢你...但是,我没有专门使用日期。


让我告诉你一个我的意思的例子 - 如果我可以给你发电子邮件,请告诉我使用示例文件,以便您更容易理解我的要求:-)


W列包含以下文本:

D09 / 17或G03 / 23 - 前面的字母是我需要的一些排序代码。因此,这就是为什么我在我的查询中使用了Like这个术语,以便我可以选择其他列有09.



嗨。


我可以尝试澄清这个问题吗?我相信你要问的是如何选择行,但是如何只显示 包含有效日期的列。正确吗?


我不知道我是否可以提供很多帮助,但我想知道每个字段的IIF()是否可用于生成有效日期或无效。


Hi all,

I need some help with a sql query I am trying to do.
I had a sheet which I copied from excel.

Currently the columns which I have are Name, Phone, W1, W2, W3, W4, W5, W6, W7.

These W columns contain dates in each of them (as Strings).

The query I want to do is to Select a Name and W cell for each person that has a 09 (ie. September) in any of the W columns. I am able to do this using the following code:

SELECT Adults.NAME, W1, W2, W3, W4, W5, W6, W7
FROM Adults
WHERE (((Adults.W1) Like ''*09/*'')) OR (((Adults.W2) Like ''*09/*'')) OR (((Adults.W3) Like ''*09/*'')) OR (((Adults.W4) Like ''*09/*'')) OR (((Adults.W5) Like ''*09/*'')) OR (((Adults.W6) Like ''*09/*'')) OR (((Adults.W7) Like ''*09/*''));

However, what I want my output to show is ONLY the September date. Right now it shows all of the other dates associated with the person. I know I get all of this extra output because my SELECT line states W1 ... W7 - but I am not sure how to change my code to result only the September stuff.

I know it sounds a bit confusing, but any help would be MUCH appreciated.

thanks

解决方案

SELECT NAME, W1, W2, W3, W4, W5, W6, W7
FROM Adults
WHERE ((Month(CDate(W1)) = 9) OR (Month(CDate(W2)) = 9)
OR (Month(CDate(W3)) = 9) OR (Month(CDate(W4)) = 9)
OR (Month(CDate(W5)) = 9) OR (Month(CDate(W6)) = 9)
OR (Month(CDate(W7)) = 9));


hi, thanks for that...however, i don''t specifically use date.

let me show you an example of what i mean - please let me know if i can email you with a sample file so that it is easier for you to understand what i am asking :-)

the columns of W contain text such as:
D09/17 or G03/23 - the letter preceding is some sort code that I need for my coumns. Hence, that is why I have used the term Like in my query so that I can select other columns which have the 09.


hi, thanks for that...however, i don''t specifically use date.

let me show you an example of what i mean - please let me know if i can email you with a sample file so that it is easier for you to understand what i am asking :-)

the columns of W contain text such as:
D09/17 or G03/23 - the letter preceding is some sort code that I need for my coumns. Hence, that is why I have used the term Like in my query so that I can select other columns which have the 09.

Hi.

Can I just try to clarify the question here? I believe what you are asking is not how to select the rows, but how to display only the column(s) containing the valid date(s). Correct?

I don''t know whether I can help much, but I wonder whether an IIF() for each field might be useful to produce either the valid date or nothing.


这篇关于SQL查询 - 返回一个特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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