473,405 Members | 2,300 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,405 software developers and data experts.

Help with query...

I want to get some information from a database in wich there are events of certain dates that I want to count and group by the date for several users.

Until now I have made the query for counting and grouping one user.

SELECT
emp.first_name || ' ' || emp.last_name AS Employee_Name,
to_char(e.start_date_time,'MM/DD/YYYY') as DATE,
count(e.start_date_time) COUNT
FROM
event e,
alignment al,
employee emp,
customer c,
event_signature es
WHERE
e.start_date_time BETWEEN TO_DATE('8/13/2007','MM/DD/YYYY') AND TO_DATE ('8/24/2007 23:59:59','MM/DD/YYYY HH24:MI:SS')
AND e.alignment_id = al.alignment_id
AND e.employee_id = emp.employee_id
AND e.customer_id = c.customer_id
AND upper(e.event_type) = 'C'
AND signature_type(+) = 'DROP'
AND emp.employee_id = 160
AND e.event_id = es.event_id (+)
AND e.event_sub_type NOT LIKE 'NV'
GROUP BY
to_char(e.start_date_time,'MM/DD/YYYY'),
emp.first_name || ' ' || emp.last_name


What I get from this:



But I want to get them all users together in one table in separate columns.

For example:



Is this Posible?
And how can I make it to work?

Please help!!
Aug 24 '07 #1
5 1274
debasisdas
8,127 Expert 4TB
for this matrix report u need to use DECODE with COUNT function.
Aug 25 '07 #2
for this matrix report u need to use DECODE with COUNT function.
Can you please explain me how could I use this in my query, I've been trying to make it work with decode and count with no luck.

Thanks for your reply
Aug 27 '07 #3
qhjghz
26
I want to get some information from a database in wich there are events of certain dates that I want to count and group by the date for several users.

Until now I have made the query for counting and grouping one user.

SELECT
emp.first_name || ' ' || emp.last_name AS Employee_Name,
to_char(e.start_date_time,'MM/DD/YYYY') as DATE,
count(e.start_date_time) COUNT
FROM
event e,
alignment al,
employee emp,
customer c,
event_signature es
WHERE
e.start_date_time BETWEEN TO_DATE('8/13/2007','MM/DD/YYYY') AND TO_DATE ('8/24/2007 23:59:59','MM/DD/YYYY HH24:MI:SS')
AND e.alignment_id = al.alignment_id
AND e.employee_id = emp.employee_id
AND e.customer_id = c.customer_id
AND upper(e.event_type) = 'C'
AND signature_type(+) = 'DROP'
AND emp.employee_id = 160
AND e.event_id = es.event_id (+)
AND e.event_sub_type NOT LIKE 'NV'
GROUP BY
to_char(e.start_date_time,'MM/DD/YYYY'),
emp.first_name || ' ' || emp.last_name


What I get from this:



But I want to get them all users together in one table in separate columns.

For example:



Is this Posible?
And how can I make it to work?

Please help!!
Do you know beforehand what are the possible USER_IDs present, then you can do use the count & decode easily.
Aug 28 '07 #4
Do you know beforehand what are the possible USER_IDs present, then you can do use the count & decode easily.

Yes I know before hand the user_id's but the problem is that I am not searching in only one table for the id's and that is where I get stuck with the decode function, I haven't use it before so I don't know how the syntax for searching in several tables for several data is like.
I've been looking at the decode syntax and definition and I think this is not the function that I need. I think that decode returns only one value and I need more than one value.
If someone know for sure that my matrix can be a result of the decode function please tell me how I can use it.

Thanks for your reply
Aug 28 '07 #5
amitpatel66
2,367 Expert 2GB
Hi,

The below query wil give me the count of no of employees joined under a particular manager on a particular day:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT
  2.       e.HIREDATE,
  3.       (SELECT COUNT(empno) FROM emp WHERE MGR = 1 AND hiredate=e.hiredate GROUP BY HIREDATE) MGR1,
  4.       (SELECT COUNT(empno) FROM emp WHERE MGR = 2 AND hiredate=e.hiredate GROUP BY HIREDATE) MGR2
  5. FROM
  6.       emp e
  7.  
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. HIREDATE    MGR1    MGR2
  2. 1/1/0005       4     8
  3. 8/28/2007       4    
  4. 8/29/2007    3           
  5.  
The performance might be on slower side if the USERID's in your case are more because u will be giving subquery for each and every USERID.
Aug 29 '07 #6

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

Similar topics

11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
8
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
5
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table,...
4
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
3
by: mcmahonb | last post by:
Hey people... I've been searching this forum for a few hours and even though this topic has been went over from many different angles; I cannot seem to figure out how to make things work on my...
4
by: n | last post by:
Hello! Here is a problem I hope you can point me to a solution. It Problem: A teacher needs to know which lesson to teach. A school has a curriculum with 26 lessons, A-Z. For a given class,...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.