Pivot Sql statement

Hi,

I have a table with the folowing structure
OrderDate      Total      Online
2/10/2007      1      Y
2/10/2007      1      N

Is it posible to convert it into the following in a single statement?
OrderDate      Online      OffLine
2/10/2007      1      1
cl5bcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ee_rleeCommented:
try this code:

Select OrderDate, SUM(IIF(Online='Y',1,0)),SUM(IIF(Online='N',1,0))
FROM table Group BY OrderDate
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sdstuberCommented:
you might want to use "total" instead of "1" in your IFF functions

or if you're using oracle, it would look like this...

select orderdate, sum(decode(online,'Y',total)) online, sum(decode(online,'N',total)) offline
from table
group by orderdate

Note, if you're using oracle 11g, pivot function is built in and would look like this....

select * from ordertable
pivot (sum(total) for on_line in ('Y' "Online", 'N' "Offline"))  
0
ee_rleeCommented:
thanks for correcting me.

it should be total instead of 1.
0
cl5bcAuthor Commented:
I used the pivot function under 2005 in the end

PIVOT (
SUM(TOTAL) FOR ONLINEORDER IN ([N],[Y])
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.