|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
Re:Get Data in adifferent way
Hi, I hope the below Query will be useful for you
Quote:
Note: test2 is a table name Thanks & Regards Sakthimeenakshi.S |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Query - General - SQL: get data in a different way |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|