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

Grouping By a To_Char

3
I'm trying to show total profit per year of publication, but my pubdate's are all in the full date format.

I tried this, but I doesn't quite work:

SELECT TO_CHAR(pubdate, 'YYYY') "Year Published", sum(quantity) * (retail - cost) "Total Profit"
FROM books JOIN orderitems USING(isbn)
GROUP BY pubdate, (retail-cost);

I get a Profit for each book, not each year, there are duplicate years.
May 9 '07 #1
3 11235
frozenmist
179 Expert 100+
Hi,
If you want to group by year do
GROUP BY TO_CHAR(pubdate, 'YYYY')

Cheers
May 10 '07 #2
chandu031
78 Expert
I'm trying to show total profit per year of publication, but my pubdate's are all in the full date format.

I tried this, but I doesn't quite work:

SELECT TO_CHAR(pubdate, 'YYYY') "Year Published", sum(quantity) * (retail - cost) "Total Profit"
FROM books JOIN orderitems USING(isbn)
GROUP BY pubdate, (retail-cost);

I get a Profit for each book, not each year, there are duplicate years.
Hi,

Try this :
Expand|Select|Wrap|Line Numbers
  1. SELECT TO_CHAR(pubdate, 'YYYY') "Year Published", sum(quantity * (retail - cost)) "Total Profit"
  2. FROM books JOIN orderitems USING(isbn)
  3. GROUP BY TO_CHAR(pubdate, 'YYYY')
  4.  
May 10 '07 #3
frozenmist
179 Expert 100+
Hi,
If you want to group by year do
GROUP BY TO_CHAR(pubdate, 'YYYY')

Cheers
you have to change sum function as
sum(quantity *(retail-cost))

Cheers
May 10 '07 #4

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

Similar topics

1
by: Amin Schoeib | last post by:
Hi, Can somebody tell me why this query don't work when I use to_date Instead of to_char By using to_char: select to_char(last_day(cast(current_date - interval '1 month' as...
3
by: Praveen | last post by:
Hi All, I have some procedures which written in Oracle. Now the requirement has come to convert those procedures into db2. I used IBM provided MTK tool to convert the procedures. The tool has...
2
by: Mark Hansen | last post by:
I'm trying to convert some schema creation scripts that were used on MS SQL Server to DB2 (v8.2) and have a problem with the following select statement (snippet) used for a view: SELECT col1,...
4
by: gimme_this_gimme_that | last post by:
What is the DB2 equivalent syntax of Oracle's : select to_char(created_date,'MM/DD/YYYY') from foo Thanks
3
by: Wei Wang | last post by:
I get compile error for this code: for i in 1..arg_count-1 LOOP RAISE NOTICE quote_literal(to_char(i, ''9'')); END LOOP; where arg_count = 3. I tried RAISE NOTICE to_char(i, ''9''); as...
14
by: Najib Abi Fadel | last post by:
Hi, i am using PostgreSQL 7.3.2 there's a bug for the date '2005-03-27' !!!!!!!!!!!!!!!!!!!!!!!!!!! SELECT to_char('2005-03-27'::date,'DD/MM/YYYY'); to_char ------------ 26/03/2005 (1 row)
0
by: richasaraf | last post by:
Hi all, Please help me out... i want to convert the to_char into number format.... please let em know how to do it... for eg: i have a statement : to_char(p_number, 'S000000') this...
1
by: Eitan M | last post by:
Hello, What is the equivalent function for : to_char (to_char is Oracle function) in access ? select to_char ( ...) from ... Thanks :)
0
by: woodsc | last post by:
Hi all, I am trying to optimize the queries in my application. Is there a performance difference between (to_char(myDate,format) < myString) and (myDate < to_date(myString, format)). ex. ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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.