473,396 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Data Mashing

Hey peoples,

Im having an issue mashing data from multiple tables together. Me as well as some co-workers have been playing with it but alas no luck.
Im sure its some newbie mistake but here it goes...

Query 1

select orgid, sum(calls) as 'Calls'
from dbo.TechL_LOps_CHandled_View
where dayid = 20080120
group by orgid
order by orgid

Output

orgid Calls
======================================
64 8
86 20
129 11
140 6
149 12
etc etc


Query 2

select orgid, sum(login_time) as 'Login Time'
from dbo.TechL_LOps_WorkLog_View
where dayid = 20080120
group by orgid
order by orgid

Output

orgid Login Time
======================================
31 49.62
64 427.05
86 523.00
129 320.85
140 125.25
etc etc


Now i want to put these together IE the following

orgid Calls Login Time
======================================
31 0 49.62
64 8 427.05
86 20 523.00
129 11 320.85
140 6 125.25
etc etc

So i figured something like

select t1.orgid, sum(t1.calls) as 'Calls', sum(t2.login_time) as 'Login Time'
from dbo.TechL_LOps_CHandled_View t1 join dbo.TechL_LOps_WorkLog_View t2
on t1.orgid = t2.orgid
where t1.dayid = 20080120
and t2.dayid = t1.dayid
group by t1.orgid
order by t1.orgid

would work but quite the opposite

Output

orgid Calls Login Time
======================================
64 96 427.05
86 80 523.00
129 33 641.70
140 6 125.25
149 72 706.74
etc etc

Not only are the calls being mulitplied for some reason but the orgid 31 record isnt showing up as well.

Any help would be really appreciated.

Thanks
Jan 31 '08 #1
2 1293
ck9663
2,878 Expert 2GB
Hey peoples,

Im having an issue mashing data from multiple tables together. Me as well as some co-workers have been playing with it but alas no luck.
Im sure its some newbie mistake but here it goes...

Query 1

select orgid, sum(calls) as 'Calls'
from dbo.TechL_LOps_CHandled_View
where dayid = 20080120
group by orgid
order by orgid

Output

orgid Calls
======================================
64 8
86 20
129 11
140 6
149 12
etc etc


Query 2

select orgid, sum(login_time) as 'Login Time'
from dbo.TechL_LOps_WorkLog_View
where dayid = 20080120
group by orgid
order by orgid

Output

orgid Login Time
======================================
31 49.62
64 427.05
86 523.00
129 320.85
140 125.25
etc etc


Now i want to put these together IE the following

orgid Calls Login Time
======================================
31 0 49.62
64 8 427.05
86 20 523.00
129 11 320.85
140 6 125.25
etc etc

So i figured something like

select t1.orgid, sum(t1.calls) as 'Calls', sum(t2.login_time) as 'Login Time'
from dbo.TechL_LOps_CHandled_View t1 join dbo.TechL_LOps_WorkLog_View t2
on t1.orgid = t2.orgid
where t1.dayid = 20080120
and t2.dayid = t1.dayid
group by t1.orgid
order by t1.orgid

would work but quite the opposite

Output

orgid Calls Login Time
======================================
64 96 427.05
86 80 523.00
129 33 641.70
140 6 125.25
149 72 706.74
etc etc

Not only are the calls being mulitplied for some reason but the orgid 31 record isnt showing up as well.

Any help would be really appreciated.

Thanks
try something like:

select orgid, sum(calls) as totalcalls, sum(logintime) as totallogintime from
(select orgid, calls, 0 as logintime from dbo.TechL_LOps_CHandled_View
union
select orgid, 0 as calls, logintime from dbo.TechL_LOps_WorkLog_View) A
group by origid

-- ck
Jan 31 '08 #2
Thank you very much, I should have posted ealier instead of wasting so much time my self heh
Jan 31 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: lawrence | last post by:
I had some code that worked fine for several weeks, and then yesterday it stopped working. I'm not sure what I did. Nor can I make out why it isn't working. I'm running a query that should return 3...
11
by: Qiangning Hong | last post by:
A class Collector, it spawns several threads to read from serial port. Collector.get_data() will get all the data they have read since last call. Who can tell me whether my implementation correct?...
0
by: Eric | last post by:
I've got a weird problem, regardless of how often I enter: perl -MCPAN -e 'install "Data::Dumper"' I never get a message telling me that it is up-to-date. It will always try to reinstall even...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
3
by: bbernieb | last post by:
Hi, All, Is it possible to access a variable inside of a data binding, without the variable being out of scope? (Note: On the DataBinder line, I get an error message that says "Name 'i' is...
5
by: Gene | last post by:
What can I do if I want to get the result using the sql command? for example, the select command is "select Name from Employee where StaffID=10" How to get the "Name"??? dim Name as string and...
5
by: DC Gringo | last post by:
I am having a problem reading a simple update to the database. Basically I'm testing a small change to the pubs database -- changing the price of the Busy Executive's Database Guide from 19.99 to...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
0
by: Winder | last post by:
Computer Data Recovery Help 24/7 Data recovering tools and services is our focus. We will recover your data in a cost effective and efficient manner. We recover all operating systems and media....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.