GROUP BY error message with IF statement

GROUP BY error message with IF statement

Hi, 

I'm reasonably new to coding so this may be a really simple fix (i hope anyway!)

I'm building a query table to identify cases for inclusion in a healthcare quality indicator as well as produce an output column that provides a true or false statement as to whether the indicator has been met. Query 1 below works fine but when I want to add another OR statement in the IF statement (shown in query 2 below query1) I get this: 
Error Details:

Query Error: Improper usage of GROUP BY clause.
Please ensure that all non-aggregate columns used in the SELECT clause are also used in GROUP BY clause.

**Query 1 - this works**

SELECT
jobs.id AS job_id,
patients.id AS patient_id,
jobs."date" AS "date",
strokes.id,
strokes."fast" AS "fast",
strokes.fast_neg AS fast_neg,
strokes.weak_side AS weakness,
strokes.face_side AS face_weakness,
strokes.resolved AS resolved,
strokes.speech AS speech,
SUM(observations.bm) AS total_bm,
MAX(bloodtests.value) AS bm,
SUM(observations.sbp) AS total_sbp,
primaries.total_gcs AS primary_gcs,
patients.mechanism_id AS mechanism_id,
jobs.cad_cat_id AS cadcat_id,
jobs.job_type AS job_type,
strokes.cb_inclusion AS cb_inclusion,
IF((strokes."fast"  = 'true'
OR strokes.weak_side  IS NOT NULL
OR strokes.face_side  IS NOT NULL
OR strokes.speech  IS NOT NULL)
AND ((SUM(observations.bm)  > 1)
OR MAX(bloodtests.value)  > 0)
AND (SUM(observations.sbp)  > 1), 'Complete CB', 'Incomplete CB') AS CB_completion
FROM  patients
JOIN jobs ON patients.job_id  = jobs.id 
LEFT JOIN strokes ON patients.id  = strokes.patient_id 
LEFT JOIN observations ON patients.id  = observations.patient_id 
LEFT JOIN bloodtests ON patients.id  = bloodtests.patient_id 
LEFT JOIN primaries ON patients.id  = primaries.patient_id  
WHERE (patients.mechanism_id  = '336'
 OR strokes.id  IS NOT NULL)
 AND (jobs."job_type"  != 'Interhospital transfer'
 AND jobs.cad_cat_id  != 44)
 AND strokes.cb_inclusion  != 'exclude'
 AND patients.id  NOT IN ( 2066  , 2115  , 3547  , 4045  , 4050  , 5782  , 5836  , 5910  )
GROUP BY jobs.id,
patients.id,
jobs."date",
strokes.id,
strokes."fast",
strokes.fast_neg,
strokes.weak_side,
strokes.face_side,
strokes.resolved,
strokes.speech,
primaries."total_gcs",
patients.mechanism_id,
jobs.cad_cat_id,
jobs.job_type,
  strokes.cb_inclusion 
ORDER BY jobs.id 


**Query 2: this produces an error**

SELECT
jobs.id AS job_id,
patients.id AS patient_id,
jobs."date" AS "date",
strokes.id,
strokes."fast" AS "fast",
strokes.fast_neg AS fast_neg,
strokes.weak_side AS weakness,
strokes.face_side AS face_weakness,
strokes.resolved AS resolved,
strokes.speech AS speech,
SUM(observations.bm) AS total_bm,
MAX(bloodtests.value) AS bm,
SUM(observations.sbp) AS total_sbp,
primaries.total_gcs AS primary_gcs,
patients.mechanism_id AS mechanism_id,
jobs.cad_cat_id AS cadcat_id,
jobs.job_type AS job_type,
strokes.cb_inclusion AS cb_inclusion,
IF((strokes."fast"  = 'true'
OR strokes.weak_side  IS NOT NULL
OR strokes.face_side  IS NOT NULL
OR strokes.speech  IS NOT NULL
         OR primaries.total_gcs <14)
AND ((SUM(observations.bm)  > 1)
OR MAX(bloodtests.value)  > 0)
AND (SUM(observations.sbp)  > 1), 'Complete CB', 'Incomplete CB') AS CB_completion
FROM  patients
JOIN jobs ON patients.job_id  = jobs.id 
LEFT JOIN strokes ON patients.id  = strokes.patient_id 
LEFT JOIN observations ON patients.id  = observations.patient_id 
LEFT JOIN bloodtests ON patients.id  = bloodtests.patient_id 
LEFT JOIN primaries ON patients.id  = primaries.patient_id  
WHERE (patients.mechanism_id  = '336'
 OR strokes.id  IS NOT NULL)
 AND (jobs."job_type"  != 'Interhospital transfer'
 AND jobs.cad_cat_id  != 44)
 AND strokes.cb_inclusion  != 'exclude'
 AND patients.id  NOT IN ( 2066  , 2115  , 3547  , 4045  , 4050  , 5782  , 5836  , 5910  )
GROUP BY jobs.id,
patients.id,
jobs."date",
strokes.id,
strokes."fast",
strokes.fast_neg,
strokes.weak_side,
strokes.face_side,
strokes.resolved,
strokes.speech,
primaries."total_gcs",
patients.mechanism_id,
jobs.cad_cat_id,
jobs.job_type,
  strokes.cb_inclusion 
ORDER BY jobs.id 

Please can you advise why it's giving me the error message?
    • Sticky Posts

    • What's New in Zoho Analytics - November 2025

      We're thrilled to announce a significant update focused on expanding your data connectivity, enhancing visualization capabilities, and delivering a more powerful, intuitive, and performant analytics experience. Here’s a look at what’s new. Explore What's
    • What's New in Zoho Analytics - October 2025

      Hello Users! We're are back with a fresh set of updates and enhancements to make data analysis faster and more insightful. Take a quick look at what’s new and see how these updates can power up your reports and dashboards. Explore What's New! Extreme
    • What’s New in Zoho Analytics – September 2025

      Hello Users!! In this month’s update, we’re raising the bar across multiple touchpoints, from how you bring in data, plan and track projects to how you design and brand your dashboards. We’ve added the all-new Gantt chart for project visualization, expanded
    • Announcing Agentic AI - Ask Zia!

      We are delighted to roll out the new agentic AI capabilities in Ask Zia, where every stage of the BI workflow is assisted by AI. With a human-in-the-loop approach, Ask Zia ensures that you’re in command of the decision, while AI handles the complexity.
    • Invitation-Based User Access in Zoho Analytics

      Hello everyone, We’re rolling out an important update on how users are added to your Zoho Analytics Organization and Workspaces. Previously, when admins added users, they were automatically added to the organization. Moving forward, to improve security
    • Recent Topics

    • Add Customer in Books on Creator Form Submit Params

      Hi guys, Were integrating a creator app with books however what were doing is adding a books customer on submit of creator form.  We have some parameters but some fields aren't coping, All were seeing is the contact name in books,.  Any help of the params for this would be great. below is a sample of the script... response = zoho.books.createRecord("contacts", "XXXXXXXXX", { "contact_name" : input.Name, "address" : input.Email }); 
    • Admin asked me for Backend Details when I wanted to verify my ZeptoMail Account

      Please provide the backend details where you will be adding the SMTP/API information of ZeptoMail Who knows what this means?
    • Suggestion : link KB with Accounts

      Hi Zoho teams.  I think it could be good to link KB articles with  : accounts in order to easily  find articles dedicated to some account specificities. I tried to use tags , but tags are free text with not easy way  to retrieve it directly from ticket or list article for one tag. Tickets : It would be a good way to measure usage of KB directly from ticket when we don't need to copy/paste KB in solution. And : Great Tool , keep going ! 
    • Drag and Drop in Creator Application

      Hi, I am in the planning phase of a new application and I would like to use 'Drag and Drop' in the user interface of my new Creator application that I am sketching out, but I don't seem to be able to find any reference that this is available to developers. In my instance I have table of entries and I would like to be able to allow users to move an entry to another table (much like you do in your own interface when creating a Pivot Table report. In addition, I would like the user to be able to re-order
    • Is there any way to integrate Zoho with Zapier?

      Is there any way to integrate Zoho with Zapier? I'd like to use it to create a workflow, sharing posts from our Wordpress website to all our channels.
    • Popular Articles Report

      From data to decisions: A deep dive into ticketing system reports Content management teams can use various metrics to assess the effectiveness of knowledge base articles, improve content quality, and ensure articles are regularly updated. Predefined article
    • Invoice Ref. Field

      Hello Team, Currently, the Invoice Ref. field is set to a Number type with a maximum limit of 9 digits. However, we often receive customer invoices that contain up to 12 digits. In some cases, the invoice reference includes not only numbers but also letters
    • 60 Days Into Zoho - Tiktok Branding Startup -7 Questions?!

      Wsp Everybody I co-own a TikTok Branding / Consulting Startup & have been using Zoho for the past 60 days - Am now looking to make our overall operations & processes more Efficient & Effective! Curious to know how others are using the platform & what's
    • Turning off the new UI

      Tried the new 'enhanced' UI and actively dislike it. Anyone know how to revert back?
    • XML format to import knowledgebase into Zoho Desk

      Hi, We just started to use Zoho Desk and want to import our knowledgebase from our old support system (Freshdesk) to Zoho Desk. Can anyone give us information about the format of xml file to import? There is no explanation on the related page.
    • Pushing Zoho People leave into Microsoft calendar: how to chose how "event" is shown (busy, free etc)

      Hi, how can I select how a "leave" event is pushed into Microsoft calendar? I want for leave "working elsewhere" to show as working elsewhere and NOT as busy.
    • Duplicate Accounts

      Hi There, I am looking for a solution, script, workflow or anything to solve an issue we have - in our customers section we have a rule that doesn't allow duplicates, however Zoho will allow customers with xxxxx and xxxxx PLC or LTD so effectivley we
    • Error with If formula

      I've got this super simple If formula, what is the reason for the error? If ( LEN(${Leads.Trial Slot Option}) == 3,'y','n') Syntax Error. Check the examples for any functions you're using to see if you formatted them correctly. Make sure your fields are
    • Announcing Multi-language Support in Zoho FSM

      Zoho FSM now speaks your language. The much-awaited multi-language support is now available in Zoho FSM. The following languages are supported in Zoho FSM: Dutch (Nederlands) English - United Kingdom English - United States French (français) French -
    • Creating multiple CRM leads from a Zoho Forms subform

      Hi all, We have a heavily used intake form that is used for new leads as a part of our intake. There is a subform that allows the lead to add additional team members, their titles and other basic info. That form submission creates a new Lead and the subform
    • Free webinar! Build smarter apps with Zoho Sign and Zoho Creator

      Hello, Bring the power of digital signatures to the apps you build in Zoho Creator! Connect Zoho Sign as a microservice and enable seamless e-signature workflows in your applications. This integration allows you to automate signing tasks using Deluge.
    • Restrict Addresses in Zoho Forms?

      In the address field, is there a way to restrict the addresses that auto populate (via Zoho Maps or Google Maps) to a specific state (I know it's possible with the country). Additionally, how often does the address in Zoho Maps get updated? Certain addresses
    • Unable to send message;Reason:553 Relaying disallowed. Invalid Domain

      i have facing the issue "Unable to send message;Reason:553 Relaying disallowed. Invalid Domain" if i verify domain evertthing i did but still face the same error.
    • ZohoMail is so close to being Perfect BUT

      Why don’t you have HILIGHTING???!! I've been trying to find a substitute for Edison Mail but I want & need hilighting (preferably in more than just yellow)! Is this even on your To Do list? I’m so disappointed. 🙄
    • Weekly Tips: Secure your attachment downloads with Zoho Mail

      Safety is one of our main concerns, whether it’s about device security or online protection. We use tools like fingerprint scanners, facial recognition, and two-factor authentication to keep our devices and email accounts secure. We use methods like OTP
    • Resume Harvester: New Enhancements for Faster Sourcing

      We’re excited to share a set of enhancements to Resume Harvester that make sourcing faster and more flexible. These updates help you cut down on repetitive steps, manage auto searches more efficiently, and review candidate profiles with ease. Why we built
    • Looking for best practices to import data from SAP Business One (on-prem) into Zoho Analytics via Zoho DataPrep / Databridge — daily automated schedule

      Hi all, I’m using SAP Business One on-prem (SQL Server / or HANA — depending on DB backend) as our ERP. I want to build a pipeline that, every morning at 9:00 AM IST: pulls transactional data (invoices, customers, products, stock, etc.) from SAP B1, loads
    • Zoho One Unified Portal - Applications

      Hello, It is great to see the work on the New Unified Customer Portal. Thanks for that. The number of applications is limited though. It is now only around the Zoho Books ecosystem (Books, Expense...) and Zoho Social. = Are other applications planned
    • Using a third party service provider want to move directly with Zoho

      Hi good day I’m currently using Zoho but I’m using a third party service provider I want to move directly with you guys I’m using Zoho email and invoices and my domain please let me know if it’s possible to move away from the third party provider my email
    • Marketing Tip #10: Start a customer loyalty program

      Winning a new customer is great, but keeping them coming back is even better. A loyalty program rewards repeat buyers with points, giving them more reasons to shop again. Over time, this builds trust and long-term relationships. Try this today: Set up
    • Zia Actions: AI-powered Workflow Automation for Faster and Smarter Execution

      Hello everyone, Updated on 12th Dec 2025 Zia actions for Workflow is available for Enterprise edition ONLY. These features are currently available in the following DCs: US, CA, EU, IN, and AU Email Auto reply and Content Generation are available as Early
    • Do Individual Forums within Categories, in Desk Community, Produce Their Own RSS Feed?

      Do Individual Forums within Categories, in Desk Community, Produce Their Own RSS Feed? If not, can anyone share a work-around that could help me get an RSS feed for individual category forums?
    • Incremental Migration Issue – Ticket Showing Resolution on Dec 9 Despite Urgent MX Cutover (Ticket ID: 152080262)

      I am experiencing an issue with Zoho Mail incremental migration from Rackspace. The initial full migration completed successfully, but the incremental migration for one mailbox failed immediately with the message: “User not exist” This appears to be a
    • Change Last Name to not required in Leads

      I would like to upload 500 target companies as leads but I don't yet have contact people for them. Can you enable the option for me to turn this requirement off to need a Second Name? Moderation update (10-Jun-23): As we explore potential solutions for
    • Resend Client Portal Invitation + View Email Delivery Status

      Hi Zoho Team, We hope you are doing well. We would like to request two important enhancements related to the Zoho Creator Client Portal invitation process. At the moment, when we add a user to the Client Portal, Zoho Creator automatically sends an invitation
    • Get user last login

      1. Is there a way to programmatically get the last user login to trigger certain workflows? 2. Is there a way to programmatically access the custom fields on a user's account?
    • Seeking Zoho Creator Expert (Delivery Management App / Logistics Ops) — Built & Deployed Before

      Hi everyone, We’re building a Delivery Management App (focused on delivery operations for now) using Zoho Creator. We’re looking for a Zoho Creator expert who has already developed and deployed a similar delivery/workflow system and can assist us with
    • Automating Employee Birthday Notifications in Zoho Cliq

      Have you ever missed a birthday and felt like the office Grinch? Fear not, the Cliq Developer Platform has got your back! With Zoho Cliq's Schedulers, you can be the office party-cipant who never forgets a single cake, balloon, or awkward rendition of
    • Copy paste from word document deletes random spaces

      Hello Dear Zoho Team, When copying from a word document into Notebook, often I face a problem of the program deleting random spaces between words, the document become terribly faulty, eventhough it is perfect in its original source document (and without
    • Adding Multiple Files to a Zoho Vault Entry

      There is a old blog post talking about adding multiple file attachments to one Zoho Vault Secret: https://www.zoho.com/blog/vault/introducing-new-features-in-zoho-vault-powerful-password-sharing-wider-storing.html Is that still possible, I can see how
    • FNB South Africa Bank Feed

      I should've thought this wouldn't work. As suspect, Zoho claims to be able to pull bank feeds from First National Bank (South Africa), but fails everytime. I suppose Xero (or even Sage One) is the way to go? If they (miraculously) get it to work again,
    • Dropshipping Address - Does Not Show on Invoice Correctly

      When a dropshipping address is used for a customer, the correct ship-to address does not seem to show on the Invoice. It shows correctly on the Sales Order, Shipment Order, and Package, just not the Invoice. This is a problem, because the company being
    • Add Attachment Support to Zoho Flow Mailhook / Email Trigger Module

      Dear Zoho Support Team, We hope you are well. We would like to kindly request a feature enhancement for the Mailhook module in Zoho Flow. Currently, the email trigger in Zoho Flow provides access to the message body, subject, from address, and to address,
    • Zoho Invoice Customer Login Portal

      Are there any plans for a customer portal to Zoho Invoice, ala Freshbooks?  I would like customers that I invoice to be able to login to review invoices and invoice history.  I have not switched from Freshbooks for this very reason.
    • the custom domain forwards by default to the old career site / how to switch it off??

      dear friends, how to switch off the old version of the career site?? The set up custom domain forwards directly to the old site, so that I cant publish it... Any ideas? Thank you! KR, Victoria
    • Next Page