来自多个表SQL的值 [英] Values from multiple tables SQL

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

问题描述

我有来自多个表和工作的代码,

我需要从另一个表添加另一个列



CONECTION IS NAME(名称)在代码是naziv),数量(代码kolicina中的名称)



我尝试过:



I HAVE CODE FROM MULTIPLE TABLES AND WORK,
I NEED TO ADD ANOTEHER COLUMN FROM ANOTHER TABLE

CONECTION IS NAME ( name in code is "naziv"), quantity (name in code "kolicina")

What I have tried:

select x1.Naziv, x1.Nabavka, (ISNULL(x2.Prodaja,0)) as Prodaja, x1.Nabavka-(ISNULL(x2.Prodaja,0)) as 'Stanje' from (select naziv, sum(kolicina) as Nabavka from  
(select naziv as naziv, convert(float, kolicina) as kolicina from mp_ulazni_racun_roba_roba union all select naziv as naziv, convert(float, kolicina) as kolicina from mp_ulazni_racun_ostalo_roba ) a 
group by naziv) x1 left join(select roba, sum(kolicina) as Prodaja from 
(select roba, convert(float, kolicina) as kolicina from mp_racun_roba union all select roba, convert(float, kolicina) as kolicina from mp_faktura_roba ) b 
group by roba) x2 on x1.naziv = x2.roba 





另一个表格栏目



ANOTHER TABLE COLUMN

select minimalna_dozvoljena_kolicina from dbo.roba_usluge

推荐答案

Gerry是对的 - SQL非常难以阅读。



但是为了便于阅读,我们可能无法帮助你:我们不知道这两个表之间的关系是什么,那就是实际获取你想要的数据非常重要。



但很可能,你需要的是某种类型的JOIN(它可能会提高质量)您原来的查询也是如此 - 但我们不知道您的数据或您想要获得的输出,因此我们无法确定)。

所以现在是时候阅读: SQL连接 [ ^ ]



哦,请大家帮个忙:不要大喊 。使用所有大写字母被认为是在互联网上大喊大叫,粗鲁(使用所有小写字母被认为是幼稚的)。如果你想被认真对待,请使用适当的大写字母。
Gerry is right - that SQL is very hard to read.

But even formatted for readability, we probably can't help you as it stands: we have no idea what the relationship between the two tables is, and that's pretty much essential to actually fetching the data you want.

But in all likelihood, what you will need is a JOIN of some type (and it would probably improve the quality of your original query as well - but we have no idea of your data or what output you are trying to get so we can't be sure).
So it's time for some reading: SQL Joins[^]

Oh, and do everyone a favour: DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.


这篇关于来自多个表SQL的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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