zoukankan      html  css  js  c++  java
  • Mysql查询比较

    创建一个表:

    article,书编码;dealer,书店;price ,书的价格。

    导入一些数据:

    INSERT INTO shop VALUES
        (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),
        (3,'C',1.69),(3,'D',1.25),(4,'D',19.95);
    需求1:
      获取价格最高的书的相关信息
      sql1:select * from shop where price in (select Max(price) from shop);
      sql2:select * from shop  order by price desc limit 1;
      sql3:select t1.* from shop t1 left join shop t2 on t1.price <t2.price where t2.price is null;
    需求2:
      找取每种价格最贵的书的相关信息
      sql1:select * from  shop where price in (select Max(price) from shop group by article);
      sql2:select s1.* from shop s1 inner join (select article,MAX(price) as price from shop group by article )s2 on s1.article=s2.article and s1.price=s2.price;
      sql3:select s1.* from shop s1 where price=(select MAX(price) from shop s2 where s1.article=s2.article);
      sql4:
    select s1.* from shop s1 left join shop s2 on s1.article=s2.article and s1.price<s2.price where s2.price is null;(优)
     

      
  • 相关阅读:
    centos7下安装Jdk8、Tomcat8
    CentOS7.3下使用YUM安装MySQL5.6
    数据库表直接生成Excel
    分页工具类
    ResponseUtil
    图片上传
    UUIDUtils
    html和js
    java
    Eclipse启动发生的错误An internal error occurred during: "Initializing Java Tooling".
  • 原文地址:https://www.cnblogs.com/itdev/p/5777372.html
Copyright © 2011-2022 走看看