需要有关SQL语句的帮助。 [英] Need help on SQL statement.

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

问题描述

我有两张表如下:

表一被命名为KLASA,它有以下两列:

这里是主键(ID_Klasa)和(KlasaViti)

表二是maed PARALELJA,它有以下三列:

主键(ID_Paralelja)(Paralelja)和(ID_Klasa)。

我是什么假装做的是进行查询以获得第一张桌子的KlasaViti和第二张桌子的Paralelja的组合。结果我想插入表二。

例如表一有ID_Klasa = 3,KlasaViti = 2,表二有ID_Paralelja = 3,Paralelja = 1。我想自动找到Klasa = 2和Paralelja = 3的组合,并从表1中获取ID_Klasa,我希望在第二个表的ID_klasa中插入该值。



我有点困惑如何做到这一点。

以下是我正在尝试的一些代码,但我没有结果:



I have two tables like following:
Table one is named KLASA which has following two columns:
here is primary key (ID_Klasa) and (KlasaViti)
Table two is maed PARALELJA which has following three columns:
primary key (ID_Paralelja) (Paralelja) and (ID_Klasa).
What I'm pretending to do is to make a query to get the combination of KlasaViti from first table and Paralelja from second table. The result of that I want to insert into table two.
for example table one has ID_Klasa=3 , KlasaViti=2, table two has ID_Paralelja=3, Paralelja=1. I want to automatically find the combination of Klasa=2 and Paralelja=3 and to get the ID_Klasa from table one, that value I want to insert at the ID_klasa at the table two.

I'm little bit confused how to do that.
Here is some code what I'm trying but I'm having no result:

SELECT k.ID_Klasa FROM [Projekti_TI_1].[dbo].[KLASA] AS k
 JOIN [Projekti_TI_1] .[dbo].[PARALELJA]  as p on
 k.KlasaViti = p.Paralelja
 where k.ID_Klasa = p.ID_Klasa





提前感谢您的支持花时间阅读这个请求。

干杯。



编辑:

可能我没有正确地提出要求。我认为下图显示了我的问题。

< img src =http://i444.photobucket.com/albums/qq165/dr_iton/SQLstatement_zps6d18d49f.jpgborder =0alt =photo SQLstatement_zps6d18d49f.jpg/>

推荐答案

我自己使用存储过程解决了我得到的值并存储在本地值中,之后我使用了该值并发送到表2中的正确列。 br />
再次感谢您的帮助。
I solved by myself using stored procedure I've got the value and stored in local value, after that I used that value and sent to the proper column in Table 2.
Once again thank you for your help.


如果您在两个表上执行内部联接,则自动它将匹配两个表上的特定列。



If you perform Inner join on two tables, Automatically it will match the particular column on both the tables.

SELECT k.ID_Klasa FROM [Projekti_TI_1].[dbo].[KLASA] AS k
 JOIN [Projekti_TI_1] .[dbo].[PARALELJA]  as p on
 k.KlasaViti = p.Paralelja
 where k.ID_Klasa = p.ID_Klasa


这篇关于需要有关SQL语句的帮助。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆