本文介绍了请帮助SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个桌子

在表1中,我具有以下字段:

I have two tables

In table1 i have following fields:

id
Name



在表2中,我有以下字段



In table2 i have following fields

tid
id
skill
proficiency



充满数据的table1看起来像



the table1 filled with data looks like

id   Name
R1  abc
R2  xyz


充满数据的table2看起来像


the table2 filled with data looks like

tid   id   skill         proficiency
1     R1   .net         high
2     R1    sql          low
3     R1    jquery    low
4     R2    .net        low


现在,我想创建一个数据表,其中将包含有关ID R1的所有信息,即名称,所有技能及其熟练程度....


now i want to create a datatable that will contain all information regarding id R1 i.e Name, all skills along with their proficiency....

推荐答案

SELECT t1.Name, t2.Skill, t2.Proficiency
FROM table1 t1
INNER JOIN table2 t2 ON t1.ID = t2.ID
WHERE t1.ID = 'R1'



这将为您提供ID为R1的名称,技能和熟练程度.



This will give you the name, skill, and proficiency where the ID is R1.


SELECT tbl1.Name, tbl2 .Skill, tbl2 .Proficiency
FROM table1 tbl1
INNER JOIN table2 tbl2 ON t1.ID = t2.ID
WHERE tbl1.ID = r1


var allRows =
    from
        dataTable1Rows in dataTable1.AsEnumerable()
    join
        dataTable2Rows in dataTable2.AsEnumerable()
    on
        dataTable1Rows.Field<int>("ID") equals dataTable2Rows.Field<int>("ID")
    select
        dataTable2Rows;

DataTable joinedDataTable = allRows.CopyToDataTable();


如果要在c#端使用此joinDataTable,则可以将其绑定到rdlc;否则,如果要使用sql server查询,则两个表之间的简单连接应该可以工作


and this joinedDataTable you can bind to rdlc , if you want to do it at c# side , otherwise if you want a sql server query a simple join between two tables should work

SELECT table1.ID ,table1.Name, table2.Skill, table2.Proficiency
FROM datatable1 table1
INNER JOIN datatable2 table2 ON table1.ID = table2.ID where table1.ID='R1'


希望这会有所帮助

问候,
Harika Kakkireni


Hope this helps

Regards,
Harika Kakkireni


这篇关于请帮助SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 21:59