skip to Main Content

How do I display the ‘like komodo’ and ‘average(amount)’ commands at the same time

can you fix my code guys
here is my code

select *
FROM komodoshop
where name like ‘%komodo’ and AVG(amount) from name;

i want to use avg and like command at the same time in MySQL

2

Answers


  1. If I understand your question correctly try this

    SELECT * 
    FROM komodoshop 
    WHERE name LIKE '%komodo' 
    AND amount >= (SELECT AVG(amount) FROM komodoshop);
    

    but when I put your question though ChatGPT I got this as the answer – which doesn’t really seem to be what you asked.

    SELECT name, AVG(amount) AS average_amount
    FROM komodoshop
    WHERE name LIKE '%komodo'
    GROUP BY name;
    

    If you have sample data, that would help me understand what you are trying to look at.

    Login or Signup to reply.
  2. SELECT ks.*, (SELECT AVG(amount) FROM komodoshop) AS average_amount
    FROM komodoshop AS ks
    WHERE ks.name LIKE '%komodo';
    
    
    SELECT name, AVG(amount) AS average_amount
    FROM komodoshop
    WHERE name LIKE '%komodo'
    GROUP BY name;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search