SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 3rd, 2009, 03:19 AM
ayaz_ncr ayaz_ncr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 1 ayaz_ncr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 22 sec
Reputation Power: 0
Query - General - SQL: get data in a different way

Hi,

I have the below table in Oracle 11g database.

Product Status Source Destination
---------------------------------------
P1, In, Null, US
P1, In, India, US
P1, In, China, US
P1, In, China, US
P1, Out, US, India
P1, Out, US, India
P1, Out, US, India
P1, Out, US, India

I need to write a SQL Select query to display the information from table in below format.

Status(In) Status(Out)
------------------------------------------------
From-China 2 To-China 0
From-India 1 To-India 4

If the source is non-US (India or China) and Status is In, get the counts of India and China from Source Column

(From India, From China).

If the source is US and Status is Out, get the counts of India and China from Destination Column (To India, To

China).

I know its easier done by writing a PL SQL code but I dont have rights to create the procedures. I have only SELECT

privileges to the database, therefore the need to write a SELECT SQL Query. Any help in this is highly appreciated.

Thanks,
Best Regards,
Ayaz

Reply With Quote
  #2  
Old May 3rd, 2009, 06:23 PM
June7 June7 is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2009
Location: The Great Land
Posts: 536 June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 13 h 58 m 7 sec
Reputation Power: 124
SQL Query

Gave it another try. Hopefully this will give you something to build from. I could not structure one query to get all the data and count.
Could do separate queries for each case:
rs.Open “SELECT (Source & Status) As SS FROM tablename GROUP BY (Source & Status) HAVING (Source & Status) = ‘ChinaIn’;”
intCount = rs.Recordcount ‘get the count of records meeting the condition.
OR one query and loop through the recordset to get counts
rs.Open “SELECT (Source & Status) AS SS FROM Problem11 GROUP BY (Source & Status);”
For i = 1 to 4
Select Case i
Case 1
strCond = “IndiaIn”
Case 2
strCond = “ChinaIn”
Case 3
strCond = “IndiaOut”
Case 4
strCond = “ChinaOut”
End Select
rs.MoveFirst
count = 0
While Not EOF
If SS = strCond then count = count +1
rs.MoveNext
Wend
‘code here to write info somewhere
Next

Last edited by June7 : May 3rd, 2009 at 08:36 PM. Reason: First attempt bad info.

Reply With Quote
  #3  
Old November 3rd, 2009, 06:01 AM
sakthi.tnj sakthi.tnj is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2009
Posts: 23 sakthi.tnj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 48 m 35 sec
Reputation Power: 0
Re:Get Data in adifferent way

Hi, I hope the below Query will be useful for you

Quote:

Select 'From'+'-'+soin.source+Cast(soin.si as varchar)as [Source_IN],
'TO'+'-'+soout.source+Cast(soout.sou as varchar)as [Source-Out]
from
(Select source,count(*)as si from test2 where source!= 'us'
group by source)soin,
(Select tbl1.source,isnull(tbl2.so,0)as sou
from
(select distinct source from test2 where source!='US')tbl1
left outer join
(Select source,destination,count(destination)as so from test2 a where a.source = 'us'and a.status = 'OUT'
group by source,destination)tbl2 on tbl1.source=tbl2.destination)soout
where soin.source=soout.source



Note: test2 is a table name

Thanks & Regards
Sakthimeenakshi.S

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Query - General - SQL: get data in a different way


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek