求简单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
相关问答:
sql的软件在哪里可以下啊!在网上找了蛮多都用不了啊
随便搞一D版吧,
迅雷第一个就可以用
2000,2005都这样
http://119.147.41.16/down?cid=0698C2D64D7D637D90A6D2482298E6717D4F15CD&t=2&fmt=-1 ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......
求个vb中的sql语句的写法,次sql语句的用法是分页程序
我写的如下:其中A是用来接收每页显示的记录的条数,B是用来接收显示的当前的页面.
sqltext="select top A * from log where id not in(select top ( ......
有这样一条SQL
Select Get_Costtaxrate(col1), Get_Tcostvalue(col1) from a
其中Get_Costtaxrate、Get_Tcostvalue都是函数,这两个函数里面都是查找一个大表,Get_Tcostvalue还需要调用Get_C ......