SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select left join
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pascal_jimi
Posting Yak Master

Azerbaijan
141 Posts

Posted - 11/07/2013 :  03:04:17  Show Profile  Visit pascal_jimi's Homepage  Reply with Quote
DECLARE @phone table(
phone int
);
insert into @phone
(phone)
values
(111)
insert into @phone
(phone)
values
(222)
insert into @phone
(phone)
values
(333)


DECLARE @servis table(
phon int ,
servis nvarchar(20)
);
insert into @servis
(phon,servis)
values
(111,'aciq')
insert into @servis
(phon,servis)
values
(111,'bagli')
insert into @servis
(phon,servis)
values
(111,'birbasa')



select phone,2 as qiymet from @phone

phone qiymet
111 2
222 2
333 2

select phon as ph ,count(phon)*0.35 as ser
from @servis group by phon

ph ser
111 1.05


how can I get in Results


phone qiymet ser
111 2 1.05
222 2 0
333 2 0







http://sql-az.tr.gg/

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 11/07/2013 :  03:21:06  Show Profile  Reply with Quote

select p.phone,2 as qiymet,coalesce(ser,0) as ser
from @phone p
left join (select phon as ph ,count(phon)*0.35 as ser
from @servis group by phon)s
on s.phon = p.phone


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

sigmas
Posting Yak Master

Belarus
172 Posts

Posted - 11/07/2013 :  04:53:28  Show Profile  Reply with Quote
no need to nested query.

select p.phone, 2 as qiymet, count(s.phon)*0.35 as ser
from @phone p
left join @servis s
on p.phone = s.phon
group by p.phone;


Edited by - sigmas on 11/07/2013 04:54:54
Go to Top of Page

pascal_jimi
Posting Yak Master

Azerbaijan
141 Posts

Posted - 11/07/2013 :  06:38:07  Show Profile  Visit pascal_jimi's Homepage  Reply with Quote
thank you very much sigmas and visakh

you is my friend

http://sql-az.tr.gg/
Go to Top of Page

sigmas
Posting Yak Master

Belarus
172 Posts

Posted - 11/07/2013 :  07:42:23  Show Profile  Reply with Quote
you are welcome glad to help

you are my friend.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000