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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:13:19+00:00 2026-05-27T07:13:19+00:00

This is my query: SELECT `i`.`itemtype` AS `Item`, `p`.`name` (SELECT SUM(`i`.`count`) AS `Count` WHERE

  • 0

This is my query:

SELECT
   `i`.`itemtype` AS `Item`,
   `p`.`name`
   (SELECT SUM(`i`.`count`) AS `Count` WHERE `itemtype` = 2148),
   (SELECT SUM(`i`.`count`) * 100 AS `Count1` WHERE `itemtype` = 2152),
   (SELECT SUM(`i`.`count`) * 10000 AS `Count2` WHERE `itemtype` = 2160)
FROM `player_items` AS `i`
LEFT JOIN `players` AS `p` ON (`p`.`id` = `i`.`player_id`)
WHERE `i`.`itemtype` IN (2148, 2152, 2160)
GROUP BY `i`.`itemtype`
LIMIT 0, 30

When I run the above query in mysql, I get this error message:

#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'SELECT SUM(`i`.`count`) AS `Count` WHERE `itemtype` = 2148)
   , (SELECT SUM(`i`' at line 4

I completely don’t understand what does that mean as I’m a begginer in MySQL.

  • 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-27T07:13:19+00:00Added an answer on May 27, 2026 at 7:13 am

    You’re missing a comma after this column:

    `p`.`name`
    

    Consider this query instead:

    SELECT i.itemtype AS Item
       , p.name
       , SUM(CASE 
                WHEN itemtype = 2148 THEN i.count
                ELSE 0
             END) AS Count
       , SUM(CASE
                WHEN itemtype = 2152 THEN i.count
                ELSE 0
             END) * 100 AS Count1
       , SUM(CASE
                WHEN itemtype = 2160 THEN i.count
                ELSE 0
             END) * 10000 AS Count2
    FROM player_items AS i
    LEFT JOIN players AS p ON i.player_id = p.id
    WHERE i.itemtype IN (2148, 2152, 2160)
    GROUP BY i.itemtype ASC
    LIMIT 0, 30
    

    To SUM those three columns together, you could:

    SELECT t.itemType AS Item, t.Count, t.Count1, t.Count2
       , SUM(t.Count1, t.Count2, t.Count3) AS Total
    FROM
    (
       SELECT i.itemtype AS Item
          , p.name
          , SUM(CASE 
                   WHEN itemtype = 2148 THEN i.count
                   ELSE 0
                END) AS Count
          , SUM(CASE
                   WHEN itemtype = 2152 THEN i.count
                   ELSE 0
                END) * 100 AS Count1
          , SUM(CASE
                   WHEN itemtype = 2160 THEN i.count
                   ELSE 0
                END) * 10000 AS Count2
       FROM player_items AS i
       LEFT JOIN players AS p ON i.player_id = p.id
       WHERE i.itemtype IN (2148, 2152, 2160)
       GROUP BY i.itemtype ASC
       LIMIT 0, 30
    ) AS t
    

    Or you could add another CASE

    SELECT i.itemtype AS Item
       , p.name
       , SUM(CASE 
                WHEN itemtype = 2148 THEN i.count
                ELSE 0
             END) AS Count
       , SUM(CASE
                WHEN itemtype = 2152 THEN i.count
                ELSE 0
             END) * 100 AS Count1
       , SUM(CASE
                WHEN itemtype = 2160 THEN i.count
                ELSE 0
             END) * 10000 AS Count2
       , SUM(CASE
                WHEN itemtype = 2148 THEN i.count
                WHEN itemtype = 2152 THEN (i.count * 100)
                WHEN itemtype = 2160 THEN (i.count * 10000)
                ELSE 0
             END) AS Total
    FROM player_items AS i
    LEFT JOIN players AS p ON i.player_id = p.id
    WHERE i.itemtype IN (2148, 2152, 2160)
    GROUP BY i.itemtype ASC
    LIMIT 0, 30
    

    The CASE statements makes it unnecessary for you to have to run your three additional SELECT statements to return the same results.

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

Sidebar

Related Questions

Hi I have written this query SELECT cl_brands.name AS Brand,DATE_FORMAT(cl_doctor_call.date_entered,'%b%y')AS MonthYear, SUM(FIND_IN_SET(CONCAT('^',cl_brands.id,'^'),cl_doctor_call_cstm.brand_discussed_c))AS No_Times_Brand_Discussed FROM
I am executing this query: SELECT voterfile_county.Name, voterfile_precienct.PREC_ID, voterfile_precienct.Name, COUNT((SELECT voterfile_voter.ID FROM voterfile_voter JOIN
This is My Query : SELECT user,name,SUM(price) FROM $tableName WHERE faktor='1' GROUP BY user
In this query: SELECT COUNT(*) AS UserCount, Company.* FROM Company LEFT JOIN User ON
this query SELECT SUM(s.msg_sent_datetime - r.date_received) AS difference returns -743726381625992.000000 but if i add
This is my base query select distinct a.projects , case when(billing_fy!=0) then(select round(((sum(cost_project)/(sum(billing_fy)/((10/12)*365)))),2) from
Say I have this query: SELECT bugs.id, bug_color.name FROM bugs, bug_color WHERE bugs.id =
I want to create this query: select Something, count(Something) as Num_Of_Times from tbl_results group
This query SELECT FirstName, LastName, NCAAStats.AccountId, College_Translator.school_name, StatTypeId, COUNT(*) AS 'Count' FROM NCAAstats INNER
This query SELECT count(data_id) FROM cdiac_data_AL WHERE (data_id >= 1 and data_id <= 30437)

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.