编程学习

Mysql 学习笔记

2016-10-27  本文已影响0人  JennyGump
SELECT * FROM lzh_order_payment_transaction;
SELECT * FROM lzh_order_payment_transaction WHERE id IN(
  SELECT MAX(id)
  FROM `lzh_order_payment_transaction` 
  WHERE `status` != 1 
  GROUP BY payment_id 
);

**if语法 if(condition, for_true, for_false) **

#创建demo表 记录考试通过情况
CREATE TABLE `demo` (
  `id` INT NOT NULL,
  `name` VARCHAR (48),
  `score` INT,
  `home_town` VARCHAR (48) NOT NULL,
  PRIMARY KEY(`id`) 
) 
DEFAULT CHARACTER SET = utf8 ;

ALTER TABLE `demo` MODIFY `id` INT NOT NULL AUTO_INCREMENT;
SELECT * FROM demo;

#插入测试数据
INSERT INTO demo (`name`, `score`, `home_town`)
VALUES
('Paul', 90, 'England'),
('Kobe', 60, 'America'),
('James', 35, 'America'),
('Durant', 59, 'Soutch Africa');

 #根据条件查看考试通过情况: 低于60分算不通过
SELECT `name`, IF(`score` >= 60, 'pass', 'faile') AS 'result' FROM demo;
上一篇 下一篇

猜你喜欢

热点阅读