Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update sql solution to lc problem: No.1435, No.2205 #1825

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions solution/1400-1499/1435.Create a Session Bar Chart/README.md
Original file line number Diff line number Diff line change
@@ -70,13 +70,13 @@ Sessions 表:
### **SQL**

```sql
SELECT '[0-5>' AS bin, count(1) AS total FROM Sessions WHERE duration < 300
SELECT '[0-5>' AS bin, COUNT(1) AS total FROM Sessions WHERE duration < 300
UNION
SELECT '[5-10>' AS bin, count(1) AS total FROM Sessions WHERE 300 <= duration AND duration < 600
SELECT '[5-10>' AS bin, COUNT(1) AS total FROM Sessions WHERE 300 <= duration AND duration < 600
UNION
SELECT '[10-15>' AS bin, count(1) AS total FROM Sessions WHERE 600 <= duration AND duration < 900
SELECT '[10-15>' AS bin, COUNT(1) AS total FROM Sessions WHERE 600 <= duration AND duration < 900
UNION
SELECT '15 or more' AS bin, count(1) AS total FROM Sessions WHERE 900 <= duration;
SELECT '15 or more' AS bin, COUNT(1) AS total FROM Sessions WHERE 900 <= duration;
```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
@@ -65,13 +65,13 @@ For session_id 5 has a duration greater than or equal to 15 minutes.
### **SQL**

```sql
SELECT '[0-5>' AS bin, count(1) AS total FROM Sessions WHERE duration < 300
SELECT '[0-5>' AS bin, COUNT(1) AS total FROM Sessions WHERE duration < 300
UNION
SELECT '[5-10>' AS bin, count(1) AS total FROM Sessions WHERE 300 <= duration AND duration < 600
SELECT '[5-10>' AS bin, COUNT(1) AS total FROM Sessions WHERE 300 <= duration AND duration < 600
UNION
SELECT '[10-15>' AS bin, count(1) AS total FROM Sessions WHERE 600 <= duration AND duration < 900
SELECT '[10-15>' AS bin, COUNT(1) AS total FROM Sessions WHERE 600 <= duration AND duration < 900
UNION
SELECT '15 or more' AS bin, count(1) AS total FROM Sessions WHERE 900 <= duration;
SELECT '15 or more' AS bin, COUNT(1) AS total FROM Sessions WHERE 900 <= duration;
```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SELECT '[0-5>' AS bin, count(1) AS total FROM Sessions WHERE duration < 300
SELECT '[0-5>' AS bin, COUNT(1) AS total FROM Sessions WHERE duration < 300
UNION
SELECT '[5-10>' AS bin, count(1) AS total FROM Sessions WHERE 300 <= duration AND duration < 600
SELECT '[5-10>' AS bin, COUNT(1) AS total FROM Sessions WHERE 300 <= duration AND duration < 600
UNION
SELECT '[10-15>' AS bin, count(1) AS total FROM Sessions WHERE 600 <= duration AND duration < 900
SELECT '[10-15>' AS bin, COUNT(1) AS total FROM Sessions WHERE 600 <= duration AND duration < 900
UNION
SELECT '15 or more' AS bin, count(1) AS total FROM Sessions WHERE 900 <= duration;
SELECT '15 or more' AS bin, COUNT(1) AS total FROM Sessions WHERE 900 <= duration;
Original file line number Diff line number Diff line change
@@ -74,11 +74,9 @@ startDate = 2022-03-08, endDate = 2022-03-20, minAmount = 1000
CREATE FUNCTION getUserIDs(startDate DATE, endDate DATE, minAmount INT) RETURNS INT
BEGIN
RETURN (
# Write your MySQL query statement below.
# Write your MySQL query statement below.
SELECT COUNT(DISTINCT user_id) AS user_cnt
FROM Purchases
WHERE time_stamp BETWEEN startDate AND endDate AND amount >= minAmount;
WHERE time_stamp BETWEEN startDate AND endDate AND amount >= minAmount
);
END
```
Original file line number Diff line number Diff line change
@@ -64,11 +64,9 @@ Out of the three users, only User 3 is eligible for a discount.
CREATE FUNCTION getUserIDs(startDate DATE, endDate DATE, minAmount INT) RETURNS INT
BEGIN
RETURN (
# Write your MySQL query statement below.
# Write your MySQL query statement below.
SELECT COUNT(DISTINCT user_id) AS user_cnt
FROM Purchases
WHERE time_stamp BETWEEN startDate AND endDate AND amount >= minAmount;
WHERE time_stamp BETWEEN startDate AND endDate AND amount >= minAmount
);
END
```
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
CREATE FUNCTION getUserIDs(startDate DATE, endDate DATE, minAmount INT) RETURNS INT
BEGIN
RETURN (
# Write your MySQL query statement below.
# Write your MySQL query statement below.
SELECT COUNT(DISTINCT user_id) AS user_cnt
FROM Purchases
WHERE time_stamp BETWEEN startDate AND endDate AND amount >= minAmount;
WHERE time_stamp BETWEEN startDate AND endDate AND amount >= minAmount
);
END
END