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.
3 11235
Hi,
If you want to group by year do
GROUP BY TO_CHAR(pubdate, 'YYYY')
Cheers
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 : -
SELECT TO_CHAR(pubdate, 'YYYY') "Year Published", sum(quantity * (retail - cost)) "Total Profit"
-
FROM books JOIN orderitems USING(isbn)
-
GROUP BY TO_CHAR(pubdate, 'YYYY')
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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,...
|
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
|
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...
|
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)
|
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...
|
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 :)
|
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. ...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
| |