美文网首页
SQL每日一题(2020-07-02)

SQL每日一题(2020-07-02)

作者: 扎西的德勒 | 来源:发表于2020-07-02 10:16 被阅读0次

    题目:

    你能写一个 SQL 查询语句,找到只出现过一次的数字中,最大的一个数字吗?下面是测试数据 image 对于上面给出的样例数据,你的查询语句应该返回如下结果: image

    参考答案:

    数据库版本:Server version: 8.0.20 MySQL Community Server - GPL

    建表语句

    create table dailytest_20200702(num int);
    

    数据准备

    insert into dailytest_20200702 values (8),(8),(3),(3),(1),(4),(5),(6);
    

    查询逻辑

    select
           num
    from dailytest_20200702
        group by num having count(1) = 1
        order by num desc
        limit 1;
    

    附:
    题目来源:https://mp.weixin.qq.com/s/QmvNQ0Zko2IEhWK3XS7C3A

    相关文章

      网友评论

          本文标题:SQL每日一题(2020-07-02)

          本文链接:https://www.haomeiwen.com/subject/bvylqktx.html