sqlserver多表查询语句
-- Create database linkselect a.,b.remark,c.content from a,b,c where patindex('%'+convert(varchar,b.id)+'%',a.fb)>0
select a., b., c.or patindex('%'+convert(varchar,c.id)+'%',a.fb)>0
select a.,b.remark,c.content from A,B,C where 'b'+ltrim(b.id) like '%'+a.fb+'%' and 'c'+ltrim(c.id) like '%'+a.fb+'%'
from a join b on a.id=b.id join c on a.id=c.id
where b.remark like '%ddd%' and c.content like '%ffff%'
求助按要求写个sql查询语句
sqlserver数据库
首先你这个是动态列,同一个id下有几个人就会出现几个客户列,这个就难了,我设你同一个id下最多2个人(多的话可以加)。
首先给同一个id编号,建一个视图
create view vw_person as
)--选出同一个id下的条数据,然后leftjoin第二条,以ID来匹配。需要多列的话不停地left --join就行
select from
(select id,idx,[客户] as [客户from (select t.,1],[号码] as [号码1] from vw_person where idx=1) a
left {string connstring = "server=127.0.0.1\\SQLEXPRESS;database=数据库名;uid=用户名;pwd=密码";//连接串,连接你的数据库join
(select id,idx,[客户] as [客户2],[号码] as [号码2] from vw_person where idx=2) b
on a.id=b.id
SQLserver两个表查询语句,实在不会写,求帮助!!
conn.Close();方法1:左连接
select from [工单领料表]a
left join [入库表]b where a.[工单单号]=b.[工单单号]
方法2:表联合
select from [工单领料表]a
union on select from [入库表]b
where a.[工单单号]=b.[工单单号]
方法1:左连接select from [工单领料表]aleft join [入库表]b where a.[工单单号]=b.[工单单号]order by a.[工单单号],b.[领料单号],b.[入库单号]方法2:表联合select from [工单领料表]aunion on select from [入库表]bwhere a.[工单单号]=b.[工单单号]
建议换思路,表之间不存在关联关系,并且数据都是整条的dbuser为用户名,password为密码
采用C#在vs2010编写查询语句如何获取SQLserver2008中的数据,求具体编写代码,急!!
别着急,很简单,看下面:
private DataTable GetTable()
SqlConnection conn = new SqlConnection(connstring);
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
dt = GetDataTable(sql);DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);//执行查询并加载数据到DataTable中
cmd.Dise();
}然后,dataGridView1.DataSourse=dt;
就可以在窗体中显示数据了。
模糊查询的话,方法和这个一样,只是把SQL改一下,where条件中加上 like 即可。
如果要求代码的完美,需要在数据层写一个单独的获取表的方法,即:
(select ,row_number() over(partition by id order by [号码] desc ) as idx from person///
/// 将数据库表读取到内存DataTable中
///
///
传入的sql字符串
public static DataTable GetDataTable(string sql)
SqlConnection conn = new SqlConnection(connstring);
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlCommand cmd = Cmd(sql);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
cmd.Dise();
}然后在业务层写一个调用的方法,传入SQL,即:
public static DataTable GetDataTableBLL()
{string sql="select from table";
DataTable dt = new DataTable();
}需要的数据不同,传入的SQL不同。
sqlserver语句查询
return dt;难道是分组?? select 属性(A、B) ,属性值(a,d,j等) from 表(数据所在表)
group by 属性(A、B);
你这有没有规律或者算法MEDIADBLINK =?
没规律,笼统讲实现不了的
sqlserver的查询语句?
selreturn dt;ect t.
row_number() over(partition by order by id desc) as rank
from 当前使用的数据库是orcl1tablename t) where = '男' and rank = 1
sql怎样跨数据库查询oracle
order by a.[工单单号],b.[领料单号],b.[入库单号]使用DBLINK。
string sql = "select from Users";//查询SQL,根据你的表来写例如:
要查询的数据库是orcl2的scott用户的表。
create public database linkorcl2_scott connect to scott identified by tiger using '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.21.2)(PORT = 1521)))(CONNECT_DATA =(SID = orcl2)))'; 其中orcl2_scott是你创建的dblink名字,orcl2是远程数据库的实例名,scott/tiger是登录到远程数据库的用户/密码。然后在本地数据库中通过dblink访问远程数据库'orcl2'中scott.emp表,sql语句如下所示select from scott.emp@orcl2_scott;
配置本地数据库的tnsnames.ora文件
$vi $ORACLE_HOME/network/admin/tnsnames.ora
添加如下行,其中DBLINK为连接名(可自定义),HOST和PORT为数据库侦听的IP及端口,SERVICE_NAME为数据库的SID,
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.1)(PORT = 1521))
)(CONNECT_DATA =
(SERVICE_NAME = db)
))
2.登录到本地数据库,创建database link
执行如下查询语句,其中MEDIADB为database link名(可自定义),MEDIADBLINK为先前在tnsnames.ora中定义的连接名,
create database link MEDIADB
connect to dbuser identified by password
using 'MEDIADBLINK';
注意:这里不会验证用户名密码的正确性
3.使用链接的数据库
3.1 查询、删除和插入数据和作本地的数据库是一样的,只不过表名需要写成“表名@database link名”,如
select from table_name@MEDIADB ;