从1个查询中的1列获得不同的结果 [英] get different result from 1 column in 1 query

查看:98
本文介绍了从1个查询中的1列获得不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,


我希望从1个查询中的1列得到不同的结果。详细结果如下:


数据库名称:数据

表名:table1

栏:id,phoneno,timeframe,mo


如果MO = 1表示MO其他MO = 0表示MT


我的查询:


使用数据

选择phoneno,sum(mo)为mo,来自table1,其中mo =''1''和mo =''0''和timeframe>'''20080110''和timeframe<' '20080111''


我的结果:


i得到的结果是0


期待结果:


第一列是phoneno,第二列是mo,其中mo = 1,第三列是mt,其中mo = 0


非常apreciate如果你可以给我正确的查询。


非常感谢


最温暖的问候,

Nicholas

解决方案


亲爱的所有人,


i希望从1列获得不同的结果1个查询。详细结果如下:


数据库名称:数据

表名:table1

栏:id,phoneno,timeframe,mo


如果MO = 1表示MO其他MO = 0表示MT


我的查询:


使用数据

选择phoneno,sum(mo)为mo,来自table1,其中mo =''1''和mo =''0''和timeframe>'''20080110''和timeframe<' '20080111''


我的结果:


i得到的结果是0


期待结果:


第一列是phoneno,第二列是mo,其中mo = 1,第三列是mt,其中mo = 0


非常apreciate如果你可以提供正确的查询。


非常感谢


最热烈的问候,

Nicholas



我想你正在寻找案例功能


- CK


< blockquote>亲爱的CK,


我搜索了CASE函数,但我真的知道如何使用它。你可以为我演示吗?


非常感谢


问候,

Nicholas

您是否介意发布表格的一些样本数据和您想要的结果?


- CK


Dear All,

i would like to get different result from 1 column in 1 query. the details result is below

database name: Data
table name: table1
column: id, phoneno, timeframe, mo

if MO=1 means MO else MO=0 means MT

my query:

use data
select phoneno, sum(mo) as mo from table1 where mo=''1'' and mo=''0'' and timeframe>''20080110'' and timeframe<''20080111''

my result:

i get the mo result is 0

expecting result:

1st column is phoneno, 2nd is mo where mo=1, 3rd is mt where mo=0

very much apreciate if you could provide me the right query.

Many Thanks

warmest regards,
Nicholas

解决方案

Dear All,

i would like to get different result from 1 column in 1 query. the details result is below

database name: Data
table name: table1
column: id, phoneno, timeframe, mo

if MO=1 means MO else MO=0 means MT

my query:

use data
select phoneno, sum(mo) as mo from table1 where mo=''1'' and mo=''0'' and timeframe>''20080110'' and timeframe<''20080111''

my result:

i get the mo result is 0

expecting result:

1st column is phoneno, 2nd is mo where mo=1, 3rd is mt where mo=0

very much apreciate if you could provide me the right query.

Many Thanks

warmest regards,
Nicholas


I think you''re looking for CASE Function

-- CK


Dear CK,

i have searched the CASE function but i dun really know how to use it. could u demostrate for me?

Many Thanks

Regards,
Nicholas


Would you mind posting some sample data of your table and your desired result?

-- CK


这篇关于从1个查询中的1列获得不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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