leetcode--database

176. Second Highest Salary

Write a SQL query to get the second highest salary from the Employee table.

+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
For example, given the above Employee table, the second highest salary is 200. If there is no second highest salary, then the query should return null.

answer:1)SELECT MAX(Salary) as SecondHighestSalary FROM Employee WHERE Salary < (SELECT MAX(Salary) FROM Employee);

    2)SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1,1; #非原创

ps:limit 1,1 第一个1是表示第二行,第二个1表示从第二行开始往后输出几行。limit 1,1表示只输出第二行。

时间: 2024-07-28 14:57:20

leetcode--database的相关文章

leetcode database题目

LeetCode有10道SQL的题目,最近学习SQL语言,顺便刷题强化一下, 说实话刷完SQL学习指南这本书,不是很难,上面的例子 跟语法规则我都能理解透, 实际中来做一些比较难的业务逻辑题,却一下子很难想起如何利用SQL来描述 还是要多刷题开阔自己的思路,把学到手的语法加以练习 应用到实际中去 197. Rising Temperature Given a Weather table, write a SQL query to find all dates' Ids with higher t

LeetCode Database: Delete Duplicate Emails

Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. +----+------------------+ | Id | Email | +----+------------------+ | 1 | [email protected] | | 2 | [email protected]

LeetCode Database: Rank Scores

Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no "holes" be

Leetcode Database All Done

至 2015-3-11

leetcode database解题记录

175 Combine Two Tables 题目:左连接Person表和Address表. select FirstName,LastName,City,State from Person p left join Address a on p.PersonId=a.PersonId; 7个case耗时1001ms(注意耗时多次提交会不同,一般相差不大,偶尔也有相差大的)   --2015/1/11 176 Second Highest Salary 题目:写一条sql语句查询Employee 

【leetcode database】Human Traffic of Stadium

X city built a new stadium, each day many people visit it and the stats are saved as these columns: id, date, people Please write a query to display the records which have 3 or more consecutive rows and the amount of people more than 100(inclusive).

[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql)

全部最新的题解可以在 我的 github 上找,欢迎 star 和 watch ~ 更新中~~ 说明 这个系列的题解包括用 C++/Java/Python 写的 leetcode 上的算法题目,和 Sql 写的 leetcode 上的数据库题目. 有些题目虽然 AC 了却还没写分析,所以这次就开坑来完成. 链接: 我的 github Leetcode Algorithms Problems Leetcode Database Problems CSDN 题解索引 001.Two_Sum (Med

LeetCode-Algorithms #001 Two Sum, Database #175 Combine Two Tables

最近两周一直感觉学习比较松懈, 打算加大一点强度, 从今天开始, 希望能在每天正常进度完成后在LeetCode上选一两题写一写, 同时学习一下高手的做法. LeetCode - Algorithms #001 Two Sum 给定一个整数数组, 找出其中两个元素, 使其和等于目标值, 返回这两个元素在原数组中的索引组成的数组. 可以假设有且只有一组正解, 且每个元素只能使用一次. 我的思路: 其实想不到什么好的方法, 遍历就好, 非常素朴的回答: 1 class Solution { 2 pub

Docker最简教程

本文旨在让你用最短的时间弄懂Docker命令操作,什么虚拟化都太泛泛了,不讲大道理,实践出真知,让你从此的日常开发和工作中在面对Docker时不再茫然失措而是得心应手.本文也不谈安装,我实在认为作为程序员,要是我在这里教你如何安装Docker,既是在浪费你的时间也是在浪费我的时间,请参考Docker安装: Docker Hub是Docker官方维护的一个公共仓库,其中已经包括了数量超过15 000 的镜像,开发者可以注册自己的账号,并自定义自己的镜像进行存储,需要的时候可以直接拿来用,同时也能够

Leetcode之Database篇

早晨和陈John一起来实验室的路上听他说起leetcode上也有数据库和shell的练习.于是拿来练练手,发现数据库的题只有几道而且做得也很快AC率也蛮高,权当复习了一下数据库的基本语法了吧. 1:Employees Earning More Than Their Managers The Employee table holds all employees including their managers. Every employee has an Id, and there is also