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 7629477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:50:44+00:00 2026-05-31T05:50:44+00:00

Say, you have a query like SELECT COUNT(*), date FROM ORDERS GROUP BY date

  • 0

Say, you have a query like

SELECT COUNT(*), date FROM ORDERS GROUP BY date ORDER BY date

but you also want to have a third “phantom/dummy field”, where it basically tells you the fraction of orders each day that are of a particular type (lets say “Utensils” and “Perishables”).

I should say that there is an additional column in the ORDERS table that has the type of the order:

order_type

The third dummy column should do something like take the count of orders on a date that have the “Utensils” or the “Perishables” type (not XOR), then divide by the total count of orders of that day, and then round to 2 decimal points, and append a percentage sign.

The last few formatting things, aren’t really important…all I really need to know is how to apply the logic in valid PLSQL syntax.

Example output

4030 2012-02-02 34.43%
4953 2012-02-03 16.66%
  • 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-05-31T05:50:46+00:00Added an answer on May 31, 2026 at 5:50 am

    You can do something like

    SELECT COUNT(*), 
           dt,
           round( SUM( CASE WHEN order_type = 'Utensils'
                            THEN 1
                            ELSE 0
                        END) * 100 / COUNT(*),2) fraction_of_utensils_orders
      FROM ORDERS 
     GROUP BY dt
     ORDER BY st
    

    If you find it easier to follow, you could also

    SELECT COUNT(*), 
           dt,
           round( COUNT( CASE WHEN order_type = 'Utensils'
                              THEN 1
                              ELSE NULL
                          END) * 100/ COUNT(*), 2) fraction_of_utensils_orders
      FROM ORDERS 
     GROUP BY dt
     ORDER BY st
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have something like this: $db=new PDO($dsn); $statement=$db->query('Select * from foo'); while
I have a query like: SELECT EXTRACT(WEEK FROM j.updated_at) as week, count(j.id) FROM jobs
I have this query select rep, companyname,count(companyname) as [count], Commission from customers group by
Say I have a query like this: select ((amount1 - amount2)/ amount1) as chg
Let's say I have this query: select * from table1 r where r.x =
Say I have this great query in my stored procedure. Select * from Temp
Let's say we have this query SELECT * FROM table And this result from
Say I have a query like this: one two three, if I replace with
Say I have a linq query select r in db.Roles where r.RoleName DOES NOT
Say I have stored a query in a variable called $query. I want to

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.