求简单sql - MS-SQL Server / 基础类
table1:
id name sub
1 q w
2 r t
3 y n
table2:
id title_id text
1 3 u
2 2 i
3 1 p
4 2 b
5 1 m
求sql语句 查询出 title_id 相同的项 并且查出在table1中 id = title_id 列的name
结果:
2 2 i r
2 2 b r
2 2 b r 第一个2是不是该为4啊?
你给的数据和结果貌似不对.
SQL code:
select a.id,b.title_id,b.text,a.sub from table1 a join table2 b on a.id=b.title_id
title_id table1中id text name
2 2 b r
2 2 i r
结果不对吧
SQL code:
--结果好像有出入
if not object_id('table1') is null
drop table table1
Go
Create table table1([id] int,[name] nvarchar(1),[sub] nvarchar(1))
Insert table1
select 1,N'q',N'w' union all
select 2,N'r',N't' union all
select 3,N'y',N'n'
Go
if not object_id('table2') is null
drop table table2
Go
Create table table2([id] int,[title_id] int,[t
相关问答:
我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例:
......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......
需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......