LeetCode MySQL 1747. 应该被禁止的Leetflex账户
文章目錄
- 1. 題目
- 2. 解題
1. 題目
表: LogInfo
+-------------+----------+ | Column Name | Type | +-------------+----------+ | account_id | int | | ip_address | int | | login | datetime | | logout | datetime | +-------------+----------+該表是沒有主鍵的,它可能包含重復(fù)項。
該表包含有關(guān)Leetflex帳戶的登錄和注銷日期的信息。
它還包含了該賬戶用于登錄和注銷的網(wǎng)絡(luò)地址的信息。
題目確保每一個注銷時間都在登錄時間之后。
編寫一個SQL查詢語句,查找那些應(yīng)該被禁止的Leetflex帳戶編號account_id。
如果某個帳戶在某一時刻從兩個不同的網(wǎng)絡(luò)地址登錄了,則這個帳戶應(yīng)該被禁止。
可以以任何順序返回結(jié)果。
查詢結(jié)果格式如下例所示:
LogInfo table:
+------------+------------+---------------------+---------------------+ | account_id | ip_address | login | logout | +------------+------------+---------------------+---------------------+ | 1 | 1 | 2021-02-01 09:00:00 | 2021-02-01 09:30:00 | | 1 | 2 | 2021-02-01 08:00:00 | 2021-02-01 11:30:00 | | 2 | 6 | 2021-02-01 20:30:00 | 2021-02-01 22:00:00 | | 2 | 7 | 2021-02-02 20:30:00 | 2021-02-02 22:00:00 | | 3 | 9 | 2021-02-01 16:00:00 | 2021-02-01 16:59:59 | | 3 | 13 | 2021-02-01 17:00:00 | 2021-02-01 17:59:59 | | 4 | 10 | 2021-02-01 16:00:00 | 2021-02-01 17:00:00 | | 4 | 11 | 2021-02-01 17:00:00 | 2021-02-01 17:59:59 | +------------+------------+---------------------+---------------------+Result table:
+------------+ | account_id | +------------+ | 1 | | 4 | +------------+ Account ID 1 --> 該賬戶從 "2021-02-01 09:00:00" 到 "2021-02-01 09:30:00" 在兩個不同的網(wǎng)絡(luò)地址(1 and 2)上激活了。它應(yīng)該被禁止. Account ID 2 --> 該賬戶在兩個不同的網(wǎng)絡(luò)地址 (6, 7) 激活了,但在不同的時間上. Account ID 3 --> 該賬戶在兩個不同的網(wǎng)絡(luò)地址 (9, 13) 激活了,雖然是同一天,但時間上沒有交集. Account ID 4 --> 該賬戶從 "2021-02-01 17:00:00" 到 "2021-02-01 17:00:00" 在兩個不同的網(wǎng)絡(luò)地址 (10 and 11)上激活了。它應(yīng)該被禁止.來源:力扣(LeetCode)
鏈接:https://leetcode-cn.com/problems/leetflex-banned-accounts
著作權(quán)歸領(lǐng)扣網(wǎng)絡(luò)所有。商業(yè)轉(zhuǎn)載請聯(lián)系官方授權(quán),非商業(yè)轉(zhuǎn)載請注明出處。
2. 解題
# Write your MySQL query statement below select distinct l1.account_id from LogInfo l1, LogInfo l2 where l1.ip_address!=l2.ip_address and l1.account_id=l2.account_id and l1.login between l2.login and l2.logout476 ms 0 B MySQL
我的CSDN博客地址 https://michael.blog.csdn.net/
長按或掃碼關(guān)注我的公眾號(Michael阿明),一起加油、一起學(xué)習(xí)進步!
總結(jié)
以上是生活随笔為你收集整理的LeetCode MySQL 1747. 应该被禁止的Leetflex账户的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 1835. 所有数对按
- 下一篇: LeetCode 1773. 统计匹配检