首首先登场录MySQL。

1. 算术运算符

–首先创设数据库TEST
CREATE DATABASE TEST
–创建表tb_user
USE TEST
CREATE TABLE [tb_user](
[name] [nvarchar] (50) NOT NULL,
[age] [int] NOT NULL,
[sex] [nvarchar] (4)
)
–表中插入测量试验数据
USE TEST
INSERT INTO [dbo].[tb_user] (name,age,sex)
values(‘张三’,’18’,’男’)
INSERT INTO [dbo].[tb_user] (name,age,sex)
values(‘李斯’,’19’,’男’)
INSERT INTO [dbo].[tb_user] (name,age,sex)
values(‘校花’,’18’,’女’)
INSERT INTO [dbo].[tb_user] (name,age,sex)
values(‘校草’,’20’,’男’)
INSERT INTO [dbo].[tb_user] (name,age,sex)
values(‘张三2′,’19’,’男’)
INSERT INTO [dbo].[tb_user] (name,age,sex)
values(‘张小花’,’19’,’女’)

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2294
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [xxx]> 

澳门微尼斯人手机版 1

–查询
SELECT * FROM TB_USER
–依照年龄排序(升序 ASC 降序DESC)升序中ASC可以不写
SELECT * FROM TB_USER ORDER BY AGE DESC

  

2.相比较运算符

–依据性别总计人数
SELECT SEX,COUNT(*) AS P_NUM FROM TB_USER GROUP BY SEX

先查看一下二进制的记录日志是还是不是张开。

澳门微尼斯人手机版 2

–查询性别为男的客户详细
SELECT NAME,AGE,SEX FROM TB_USER WHERE SEX=’男’

MariaDB [xxx]> show variables where Variable_name="general_log";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| general_log   | ON    |
+---------------+-------+
1 row in set (0.01 sec)
注意NULL值不能用= 运算符
SELECT * FROM t WHERE c =NULL;
-- 需要改成
SELECT * FROM t WHERE c IS NULL;
-- 或改成
SELECT * FROM t WHERE c <=> NULL;
--between 相当于  a>=min  and  a<=max的运算
-- 包含则返回1, 否则为0
SELECT 'abcdef' REGEXP 'ab', 'abedefg' REGEXP 'k' k;

–查询客商中最新岁纪
SELECT MAX(AGE) FROM TB_USER

  

  澳门微尼斯人手机版 3

–查询客商中幽微年龄
SELECT MIN(AGE) FROM TB_USER

自己这里看起来是开荒的,假若是OFF。则必要开垦那几个选项:

3.逻辑运算符又叫布尔运算符。用来确认表明式的真和假。

–查询最大龄的顾客(最小同理将MAX函数换为MIN)
SELECT * FROM TB_USER WHERE AGE=(SELECT MAX(AGE) FROM TB_USER)

set global general_log=on;

澳门微尼斯人手机版 4

–求男女平均年龄
澳门微尼斯人手机版,SELECT SEX, AVG(AGE) AS AVG_AGE FROM TB_USER GROUP BY SEX

  

澳门微尼斯人手机版 5

–依照岁数总计人数
SELECT AGE,COUNT(*) AS NUM FROM TB_USER GROUP BY AGE

接下来确认一下暗中认可的log发生在哪个地方:

     not 或!  表示逻辑非。 重返和操作数相反的结果,当操作数为0(假)
重临1。 如下

–查询姓张的子女子数
SELECT SEX,COUNT(*) AS NUM FROM TB_USER WHERE NAME LIKE’张%’ GROUP BY
SEX
–查询姓张的男女孩子数行列调换
SELECT
CASE SEX WHEN ‘男’ THEN COUNT(*) ELSE 0 END AS 男,
CASE SEX WHEN ‘女’ THEN COUNT(*) ELSE 0 END AS 女
FROM TB_USER WHERE NAME LIKE ‘张%’ GROUP BY SEX

MariaDB [xxx]> show variables where Variable_name="general_log_file";
+------------------+-----------------+
| Variable_name    | Value           |
+------------------+-----------------+
| general_log_file | 10-0-236-38.log|
+------------------+-----------------+
1 row in set (0.00 sec)
 SELECT  NOT 1 ,NOT 2,NOT 0,NOT NULL,NOT NOT NULL;

发表评论

电子邮件地址不会被公开。 必填项已用*标注