求简单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
相关问答:
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......
有TABLEA 字段为 采购单号、行号、物料编码、入库日期
现想按照物料编码查询最大入库日期
语句如下:
SELECT 采购单号、行号、物料编码、入库日期 from TABLEA A WHERE 入库日期=(SELECT MAX(入库日期 ......