Home > Software engineering >  print 2 conditions in mysql
print 2 conditions in mysql

Time:12-07

I have a table in mysql witch I have to print in mysql:

List only the name and weight of all the parts except the Red parts whose weight is greater than 15.0.

I've been trying to do it but i couldn't.

CREATE TABLE parts (
  partNum CHAR(2) NOT NULL,
  name CHAR(10) NOT NULL,
  colour CHAR(8) NOT NULL,
  weight DECIMAL(3,1) NOT NULL,
  city VARCHAR(10) NOT NULL,
  PRIMARY KEY  (partNum)
);

CodePudding user response:

List SELECT only the name and , weight FROM of all the parts except WHERE NOT ( the Red parts COLOUR = 'Red' whose AND weight is greater than >= 15.0

SELECT name, weight 
FROM parts 
WHERE NOT ( COLOUR = 'Red' AND weight >= 15.0 );

CodePudding user response:

SELECT `name`, `weight` 
FROM `parts` 
WHERE NOT ( `colour` = 'Red' AND `weight` > 15 );
  • Related