Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to write sql select query right

Author  Topic 

Timur
Starting Member

1 Post

Posted - 2014-03-23 : 09:03:38
Hello dear programmers,

I have select query and how to write it right

quote:

SELECT inputdata, '???????? ??????', SUM(price) FROM numbers WHERE subdiller_id='1026' group by inputdata union
select data, ('???? ?' + nakl +'/' +comment)as comments, price from main_report WHERE subdiller_id='1026' union
select MAX(data), s.service_name, SUM(ms.price) FROM main_service ms, service s WHERE subdiller_id='1026' and ms.service_id = s.service_id group by s.service_name



My result:



???? ?????????? ?????
2014-03-20 1_?1000 50
2014-03-22 ???????? ?????? 58
2014-03-22 2_?2000 20
2014-03-22 3_?3000 30
2014-03-22 ???? ?1/900/20?? ????*5 ???+33 ?? ???*3,2 200
2014-03-22 ???? ?2/900/??????????????*5????????*?????,2653 100



I need like this result



???? ?????????? ?????
2014-03-20 1_?1000, 2_?2000, 3_?3000 100
2014-03-22 ???????? ?????? 58
2014-03-22 ???? ?1/900/20?? ????*5 ???+33 ?? ???*3,2 200
2014-03-22 ???? ?2/900/??????????????*5????????*?????,2653 100


Thank you a lot for all of you!!!

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-03-23 : 18:06:36
What is the rule that you used to combine 1_?1000, 2_?2000, 3_?3000 into one row (and leave the others alone?)
Go to Top of Page

Monib
Starting Member

11 Posts

Posted - 2014-03-24 : 02:32:27
Place a subQuery above your Query like it,

select Required_Columns
from
(
SELECT inputdata, '???????? ??????', SUM(price) FROM numbers WHERE subdiller_id='1026' group by inputdata union
select data, ('???? ?' + nakl +'/' +comment)as comments, price from main_report WHERE subdiller_id='1026' union
select MAX(data), s.service_name, SUM(ms.price) FROM main_service ms, service s WHERE subdiller_id='1026' and ms.service_id = s.service_id group by s.service_name
)
-- group by if needed

Monib
Go to Top of Page
   

- Advertisement -