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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:04:45+00:00 2026-06-15T01:04:45+00:00

i want to sort these elements either ascending / descending. Part of query: sum(CASE

  • 0

i want to sort these elements either ascending / descending.

Part of query:

sum(CASE WHEN a.question_id=39 AND u.answer_id =215 THEN 1 ELSE 0 END) as optcount1,
sum(CASE WHEN a.question_id=39 AND u.answer_id =216 THEN 1 ELSE 0 END) as optcount2,
sum(CASE WHEN a.question_id=39 AND u.answer_id =217 THEN 1 ELSE 0 END) as optcount3,
sum(CASE WHEN a.question_id=39 AND u.answer_id =218 THEN 1 ELSE 0 END) as optcount4,

Full query:

 SELECT 39 AS ques_id,215 as optid1,216 as optid2,217 as optid3,218 as optid4, 
'Easy to start the business' as optans1,
'Lower tax rate than a corporation' as optans2,
'Liability is shared' as optans3,
'Owner has total control and say over business' as optans4, 
sum(CASE WHEN a.question_id=39 AND u.answer_id =215 THEN 1 ELSE 0 END) as optcount1,
sum(CASE WHEN a.question_id=39 AND u.answer_id =216 THEN 1 ELSE 0 END) as optcount2,
sum(CASE WHEN a.question_id=39 AND u.answer_id =217 THEN 1 ELSE 0 END) as optcount3,
sum(CASE WHEN a.question_id=39 AND u.answer_id =218 THEN 1 ELSE 0 END) as optcount4, 
'217' as answer, 4 as count FROM `user_training_answers_statistics` as u,
answers as a WHERE a.question_id='39' AND u.answer_id=a.answer_id

Anyone please give me the solution for this..

  • 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-15T01:04:46+00:00Added an answer on June 15, 2026 at 1:04 am

    Wrap it in another query then do the sorting:

      select * from
        (SELECT 39 AS ques_id,215 as optid1,216 as optid2,217 as optid3,
                218 as optid4, 'Easy to start the business' as optans1,
                'Lower tax rate than a corporation' as optans2,
                'Liability is shared' as optans3,
                'Owner has total control and say over business' as optans4, 
                sum(CASE WHEN a.question_id=39 AND u.answer_id =215 THEN 1 ELSE 0 END) 
                as optcount1,
                sum(CASE WHEN a.question_id=39 AND u.answer_id =216 THEN 1 ELSE 0 END) 
                as optcount2,
                sum(CASE WHEN a.question_id=39 AND u.answer_id =217 THEN 1 ELSE 0 END) 
               as optcount3,
               sum(CASE WHEN a.question_id=39 AND u.answer_id =218 THEN 1 ELSE 0 END) 
               as optcount4, '217' as answer, 4 as count 
         FROM user_training_answers_statistics as u,
              answers as a
         WHERE a.question_id='39' AND u.answer_id=a.answer_id) as tmpTable
     ORDER BY optcount1, optcount2, optcount3, optcount4 ASC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a problem within PHP where I want to sort these posts
I want to sort a mutable array by date. My array contains several dict
I want to sort the items that have been previously selected with checkboxes. If
I want to sort items in ListBox in aspx.net. I'm binding Datasource to my
I want to sort a NSMutableArray which has NSArrays with respect to the value
I want to sort list items by their priority, which the user types in,
I want to sort ListView items by the content of second column (which can
I want to sort a list of integer values, but before sorting them I
I want to sort an array by 'hits', but I also want to look
i want to sort dictionary based upon value of each dictioanry item.but if i

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.