473,386 Members | 1,748 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,386 software developers and data experts.

help in query

any can help me. iam new in oracle.

i have a table like this

key || datetime || amount

where key is varchar(7) and amount is number

i want make some view that show sum of amount per a mounth and look like this

key || year || amount_jan || amount_feb || amount_mar || amount_apr || .....

the problem is i can show the entry if the data dont have a mounth that related.
example :

key || datetime || amount
1 1/1/07 65
1 2/3/07 68
1 3/1/07 56
1 4/1/07 46
1 5/1/07 73
1 6/1/07 12
1 7/1/07 3
1 8/1/07 98
1 9/1/07 15
1 10/1/07 87
1 11/1/07 65
1 12/1/07 86
2 2/1/07 58
2 3/1/07 35
2 6/1/07 6


the result for query is

key || year || amount_jan || amount_feb || amount_mar || amount_apr ||
1 2007 65 68 56 46

amount_may || amount_jun || amount_jul || amount_aug || amount_sep ||
73 12 3 98 15

amount_oct || amount_nov || amount_des ||
87 65 86

the entry for key = 2 is not appears. i want to show it event the month is not exist and the value for that month is 0. any can help me? please... iam have try it for 3 weeks and i still dont get it.
Aug 13 '07 #1
2 1583
hi all. anyone can help me. iam new in oracle.

i have a table like this

key || datetime || amount

where key is varchar(7) and amount is number

i want make some view that show sum of amount per a mounth and look like this

key || year || amount_jan || amount_feb || amount_mar || amount_apr || .....

the problem is i can show the entry if the data dont have a month that related.
example :

key || datetime || amount
1 1/1/07 65
1 2/3/07 68
1 3/1/07 56
1 4/1/07 46
1 5/1/07 73
1 6/1/07 12
1 7/1/07 3
1 8/1/07 98
1 9/1/07 15
1 10/1/07 87
1 11/1/07 65
1 12/1/07 86
2 2/1/07 58
2 3/1/07 35
2 6/1/07 6

i use this query :

[SELECT t1.key, to_char(t1.datetime,'YYYY'), t1.amount as amount_jan, t2.amount as amount_feb, ....., t12.amount as amount_des
FROM table t1, table t2, ..... table t12
WHERE t2.key = t1.key and t3.key = t1.key and .... and t12.key = t1.key and
to_char(t2.datetime,'YYYY') = to_char(t1.datetime,'YYYY') and .... and to_char(t12.datetime,'YYYY') = to_char(t1.datetime,'YYYY') and
to_char(t1.datetime,'MM') = '01 and .... and to_char(t12.datetime,'YYYY') = '12']

the result for query is

key || year || amount_jan || amount_feb || amount_mar || amount_apr ||
1 2007 65 68 56 46

amount_may || amount_jun || amount_jul || amount_aug || amount_sep ||
73 12 3 98 15

amount_oct || amount_nov || amount_des ||
87 65 86

the entry for key = 2 is not appears. i want to show it event the month is not exist and the value for that month is 0. any can help me? please... i have try it for 3 weeks and i still dont get it.
Aug 15 '07 #2
Anila
12
If you have n tables together, you need a n-1 join condintions. for example you have 4 tables, minimum of 3 conditions.

once you check in where condition with another tables.






hi all. anyone can help me. iam new in oracle.

i have a table like this

key || datetime || amount

where key is varchar(7) and amount is number

i want make some view that show sum of amount per a mounth and look like this

key || year || amount_jan || amount_feb || amount_mar || amount_apr || .....

the problem is i can show the entry if the data dont have a month that related.
example :

key || datetime || amount
1 1/1/07 65
1 2/3/07 68
1 3/1/07 56
1 4/1/07 46
1 5/1/07 73
1 6/1/07 12
1 7/1/07 3
1 8/1/07 98
1 9/1/07 15
1 10/1/07 87
1 11/1/07 65
1 12/1/07 86
2 2/1/07 58
2 3/1/07 35
2 6/1/07 6

i use this query :

[SELECT t1.key, to_char(t1.datetime,'YYYY'), t1.amount as amount_jan, t2.amount as amount_feb, ....., t12.amount as amount_des
FROM table t1, table t2, ..... table t12
WHERE t2.key = t1.key and t3.key = t1.key and .... and t12.key = t1.key and
to_char(t2.datetime,'YYYY') = to_char(t1.datetime,'YYYY') and .... and to_char(t12.datetime,'YYYY') = to_char(t1.datetime,'YYYY') and
to_char(t1.datetime,'MM') = '01 and .... and to_char(t12.datetime,'YYYY') = '12']

the result for query is

key || year || amount_jan || amount_feb || amount_mar || amount_apr ||
1 2007 65 68 56 46

amount_may || amount_jun || amount_jul || amount_aug || amount_sep ||
73 12 3 98 15

amount_oct || amount_nov || amount_des ||
87 65 86

the entry for key = 2 is not appears. i want to show it event the month is not exist and the value for that month is 0. any can help me? please... i have try it for 3 weeks and i still dont get it.
Aug 16 '07 #3

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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.