Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8681759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:35:38+00:00 2026-06-12T21:35:38+00:00

I have below data, I want to retrieve as single row. Customer customer id

  • 0

I have below data, I want to retrieve as single row.

Customer

customer id    customer name  order id

1               Jhon           1

2                philips       1

Order id   order name  order status   order status time
----------------------------------------------------------------    
   1       iphone      delivered      20121011 12:10:01
   1       iphone      cancelled      20121011 14:30:00  

Based on above data, I have to display as below

order id  order name  order status(D)  order status(C) order status(c) time  order status(D) time
------------------------------------------------------------------------------------------------    
   1      iphone      delivered        cancelled       20121011 14:30:00     20121011 12:10:01

Please help me to write this SQL

Regards,

Chaitu

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:35:39+00:00Added an answer on June 12, 2026 at 9:35 pm

    You can use an aggregate function and a CASE statement for this:

    select orderid,
      ordername,
      max(case when orderstatus = 'delivered' then orderstatus end) OrderStatusD,
      max(case when orderstatus = 'cancelled' then orderstatus end) OrderStatusC,
      max(case when orderstatus = 'delivered' then orderstatustime end) OrderStatusDTime,
      max(case when orderstatus = 'cancelled' then orderstatustime end) OrderStatusCTime
    from yourtable
    group by orderid, ordername
    

    See SQL Fiddle with Demo

    Based on your comments, you can use the following:

    select * 
    from 
    (
      select c.*, 
        row_number() over(partition by orderid order by customerid) rn
      from customer c
    ) c
    inner join
    (
      select orderid,
        ordername,
        max(case when orderstatus = 'delivered' then orderstatus end) OrderStatusD,
        max(case when orderstatus = 'cancelled' then orderstatus end) OrderStatusC,
        max(case when orderstatus = 'delivered' then orderstatustime end) OrderStatusDTime,
        max(case when orderstatus = 'cancelled' then orderstatustime end) OrderStatusCTime
      from yourtable
      group by orderid, ordername
    ) table1
      on c.orderid = table1.orderid
      and c.rn = 1
    

    See SQL Fiddle with Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two table (below codes) , want to retrieve last row of trackers_data
i have data below from streaming: 'ID|20120206|080500|0000001|0|1|record1|END' 'ID|20120206|080500|0000002|0|1|record2|END' 'ID|20120206|080500|0000003|0|1|record3|END' and i want to process
I have a table that contains the below data I want to write a
I have below sample data. AID Date Title ----- ---------- ------ 1 2011-12-12 test1
If i have the below data: route_name updatedDate route_id FF 15/06/2012 0:00 22 DD
I have the data below saved as a pandas dataframe . With this data,
I have data like below AAAAAA BBBBBB CCCCCC DDDDDD EEEEEE Now there is a
I have the below markup that cannot be changed: <div>Some data</div> <span>More data</span> <a>Link
I have a table that has data like below(sorted by date) COL_A | COL_B
I have the code below : public class Anything { public int Data {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.