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

  • Home
  • SEARCH
  • 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 7432707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:30:03+00:00 2026-05-29T09:30:03+00:00

I have tried to rewrite the below query, so that it will work in

  • 0

I have tried to rewrite the below query, so that it will work in a PHP page, but I have not been able to find any documentation on how the “;WITH” statement can be used in PHP, or how to make the same effect with a valid PHP Query.. The Query works perfect when executet in MS SQL 2008 R2 Management Studio, but it gives errors when I try to load it into MSSQL PHP Generator from SQLMaestro.

The query is:

;WITH UserStars AS
(
    SELECT a.username, ROUND(AVG(CAST(b.stars AS FLOAT)),1) Stars
    FROM score b
    JOIN game_users a ON a.id = b.game_users_id
    GROUP BY a.username
)
SELECT  CASE WHEN Stars < 1.4 THEN 'StarAmount1'
        WHEN Stars BETWEEN 1.4 AND 2.4 THEN 'StarAmount2'
        WHEN Stars BETWEEN 2.4 AND 3.4 THEN 'StarAmount3'
        WHEN Stars BETWEEN 3.4 AND 4.4 THEN 'StarAmount4'
        WHEN Stars BETWEEN 4.4 AND 5.0 THEN 'StarAmount5' ELSE 'AnotherStarAmount' END         StarAmount,
        COUNT(*) Users
FROM UserStars
GROUP BY CASE WHEN Stars < 1.4 THEN 'StarAmount1'
         WHEN Stars BETWEEN 1.4 AND 2.4 THEN 'StarAmount2'
         WHEN Stars BETWEEN 2.4 AND 3.4 THEN 'StarAmount3'
         WHEN Stars BETWEEN 3.4 AND 4.4 THEN 'StarAmount4'
         WHEN Stars BETWEEN 4.4 AND 5.0 THEN 'StarAmount5' ELSE 'AnotherStarAmount' END

Could someone point me in the right direction, so that the same query could be used in both PHP and in MS SQL 2008 R2 management studio?

  • 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-29T09:30:03+00:00Added an answer on May 29, 2026 at 9:30 am

    Try it like this:

    SELECT  CASE WHEN Stars < 1.4 THEN 'StarAmount1'
            WHEN Stars BETWEEN 1.4 AND 2.4 THEN 'StarAmount2'
            WHEN Stars BETWEEN 2.4 AND 3.4 THEN 'StarAmount3'
            WHEN Stars BETWEEN 3.4 AND 4.4 THEN 'StarAmount4'
            WHEN Stars BETWEEN 4.4 AND 5.0 THEN 'StarAmount5' ELSE 'AnotherStarAmount' END         StarAmount,
            COUNT(*) Users
    FROM (SELECT a.username, ROUND(AVG(CAST(b.stars AS FLOAT)),1) Stars
        FROM score b
        JOIN game_users a ON a.id = b.game_users_id
        GROUP BY a.username) UserStars
    GROUP BY CASE WHEN Stars < 1.4 THEN 'StarAmount1'
             WHEN Stars BETWEEN 1.4 AND 2.4 THEN 'StarAmount2'
             WHEN Stars BETWEEN 2.4 AND 3.4 THEN 'StarAmount3'
             WHEN Stars BETWEEN 3.4 AND 4.4 THEN 'StarAmount4'
             WHEN Stars BETWEEN 4.4 AND 5.0 THEN 'StarAmount5' ELSE 'AnotherStarAmount' END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to rewrite my url so that it removes php extention and
I have tried to find how to create DLL-s on linux using google, but
I have a php page that displays rows from a mysql db as a
UPDATE I tried using the internal wordpress rewrite. What I have to do is
I have tried this... Dim myMatches As String() = System.Text.RegularExpressions.Regex.Split(postRow.Item(Post), \b\#\b) But it is
I have tried to integrate the Picasa API on iPhone, compiles fine, but I
I have tried different examples to filter a gridview by dropdownlist, but is it
I have a page name page.php and my url as localhost/mysite/page.php , now how
I have a below code in mod-rewrite.txt RewriteEngine On RewriteRule /\.htaccess$ - [F] RewriteCond
I have a sql query in MySQL and I want an expression that matches

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.