A:表
--------------------------------
type | userid | text
------------------------------B:表
----------------------------------
userid | name
----------------------------------查询A表 要的到的结果为
--------------------------------
type | userid | text | name
------------------------------
如果 A表的 type=1 就在B表中找userid相同的name列出来
如果 A标的 type!=1 就 用一个字符串代替??请教!!!!!!!!!!
--------------------------------
type | userid | text
------------------------------B:表
----------------------------------
userid | name
----------------------------------查询A表 要的到的结果为
--------------------------------
type | userid | text | name
------------------------------
如果 A表的 type=1 就在B表中找userid相同的name列出来
如果 A标的 type!=1 就 用一个字符串代替??请教!!!!!!!!!!
解决方案 »
- 谁能给讲解下函数依赖啊
- 求SQL 两个表合并 ..一条记录加入多条记录
- com.microsoft.sqlserver.jdbc.SQLServerException
- 无法检索为此请求的数据。 (Microsoft.SqlServer.Management.Sdk.Sfc)
- 关于SQLSERVER2005的分区
- SQL SERVER 2005数据库表里的时间比系统时间晚8个小时
- 有ms sqlserver数据库导入oracle经验的dx帮帮忙!!!
- 如何在Sql Server中用SQL语句得到表的结构信息?
- 急急急.请各位大虾帮帮忙啊!
- eclipse如何创建一个项目并运行?
- 如何在一个字符串的最前和最后分别加上一个括号?
- 请问各位高手,存储过程能传入表名吗?
select a.*,b.name
from a ,b where a.userid=b.userid
union all select type,a.userid,text,'aaa' from a如果 A表的 type=1 就在B表中找userid相同的name列出来
如果 A标的 type!=1 就 用一个字符串'aaa'代替
union all select type,a.userid,text,'aaa' from a where type <> 1如果 A表的 type=1 就在B表中找userid相同的name列出来
如果 A标的 type!=1 就 用一个字符串'aaa'代替
,text,
name=case type when 1 then b.name else '字符串' end
from a ,b where a.userid=b.userid