zoukankan      html  css  js  c++  java
  • 常用sql

    查询某个字段以某个字母开头的数据

    模糊查询:select * from table_name where col_name like 'Y%';

    select * from table_name where col_name like 'Y_';  ---其中'_'代表只能有一个字符

    select * from students where name like '__'; ---查询姓名为2个字的学生

    正则表达式查询:select * from table_name where col_name regexp '^Y';

    查询多个字段的重复行

    如:学生信息表t_stu(no,name,phone,address),主键是no,各列对应学号、姓名、电话、地址,

           学生成绩表t_stu_grade(no,lesson,grade),no是表t_stu的外键,各列对应学号、科目、成绩。

    查询t_stu_grade中存在同一学生,同一科目是否有重复行,并返回该些学生的学号、姓名、电话、地址

    select * from t_stu_grade where no in(SELECT no from t_stu group by no,lesson having count(*)>1);

    消除重复数据

    select distint age,class from students;

    select distint * from students;

  • 相关阅读:
    中间件面试总结
    1.angular js 学习网址
    摄影构图
    mybatis学习(四)
    mybatis学习(三)
    mybatis学习(二)
    mybatis 学习(一)
    mysql 使用过程中出现问题
    springboot
    java 关键字
  • 原文地址:https://www.cnblogs.com/peiya/p/12655621.html
Copyright © 2011-2022 走看看