根据列数据选择查询 [英] select query according to column data

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

问题描述

我有一个表名数据:

有两列名称和工作:

1名称:arun,kapil,rahul,monu;

2工作:老师,学生,老师,学生;



i想要一个显示如下结果的查询:

姓名工作
arun老师
rahul老师
kapil学生
monu学生



i使用该查询:

 选择 * 来自数据其中 work = teacher  UNION  选择 * 来自数据其中 work = student 





但它根据我不起作用,所以plz帮我

解决方案

我觉得很简单

选择 * 来自 
data 其中
中工作' teacher'' student'





应该做的工作,除非我误解了这个问题或你没有提出问题。


使用这个



 选择 * 来自数据其中工作喜欢 '  teacher' 
UNION
< span class =code-keyword>选择 * 来自数据其中工作喜欢 ' student'


i have a table name data:
which have two columns name and work:
1 name: arun,kapil,rahul,monu;
2 work:teacher,student,teacher,student;

i want a query that show result like this:

name     work
arun     teacher
rahul    teacher
kapil    student
monu     student


i use that query:

select * from data where work=teacher UNION select * from data where work=student



but it not work according to me, so plz help me

解决方案

I think simple

select * from
data where work in ('teacher','student')



should do the job unless I have misunderstood the question or you have not presented the question.


use this one

select * from data where work like 'teacher' 
UNION 
select * from data where work like 'student'


这篇关于根据列数据选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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