子查询无法正常工作 [英] subquery is not working correctly

查看:100
本文介绍了子查询无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,



 选择 MyCountry 
< span class =code-keyword> from

select countryname 来自国家/地区)MyCountry
)a







此类查询我我试图按照我的要求生成我试过这个..



但是出于某种原因我正在犯一个错误..我做错了什么?



请建议

解决方案

如果你想为每一列提供一个子查询并且一次有多个列,那么就像这样使用< br $>


 选择 MyCountry,MyCountry1 
from

SELECT select countryname 来自国家/地区) AS MyCountry,
选择 countryname 来自国家/地区) AS MyCountry1
)a





但在这种情况下你需要在子查询中有where子句,以便它返回一个值。


 选择 [位置] 
来自 [dbo]。[department] WHERE
DEPT_NO IN 选择 [dept_no] 来自部门)







您尝试这样做,如果条件如何执行子查询....


试试这个,
选择 a.column1 as Mycountry1,a.column2 as Mycountry2,a.column3 as Mycountry2
from

选择 column1,column2,column3 来自 ))一


Hii ,

select MyCountry
from
(
(select countryname from Country) MyCountry
)a




This type of query i am trying to generate as per my requirement i tried this ..

but for some reason i am geeting an error .. m i doing something wrong ??

please suggest

解决方案

if you want one subquery for each column And multiple columns at a time then use like this

select MyCountry,MyCountry1
from
(
SELECT (select countryname from Country) AS MyCountry,
       (select countryname from Country) AS MyCountry1
)a



But in this case you need to have where clause in the subquery, so that it will return one value.


select [location]
from [dbo].[department] WHERE
DEPT_NO IN (select [dept_no] from department )




you try like this with out where condition how can you execute sub query....


Try this one,
select a.column1 as Mycountry1,a.column2 as Mycountry2,a.column3 as Mycountry2
from
(
(select column1,column2,column3 from table))a


这篇关于子查询无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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