Skip to content

Commit b80c837

Browse files
authored
Merge pull request #28 from Shoaib19/Shoaib019
query solved
2 parents f2e9df8 + c686122 commit b80c837

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed
Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
1-
Write an SQL query to find username and count of invoices from user and invoice table.
1+
-- Write an SQL query to find username and count of invoices from user and invoice table.
22

3-
Return the result table in any order.
4-
# Write your MySQL query statement below
3+
-- Return the result table in any order.
4+
-- Write your MySQL query statement below
5+
-- create a table
6+
CREATE TABLE user (
7+
id INTEGER PRIMARY KEY,
8+
name TEXT NOT NULL,
9+
gender TEXT NOT NULL
10+
);
11+
12+
CREATE TABLE invoice (
13+
id INTEGER PRIMARY KEY,
14+
name TEXT NOT NULL,
15+
total INTEGER NOT NULL,
16+
user_id INTEGER,
17+
FOREIGN KEY (user_id) REFERENCES user(id)
18+
);
19+
-- insert some values
20+
INSERT INTO user VALUES (1, 'Ryan', 'M');
21+
INSERT INTO user VALUES (2, 'Joanna', 'F');
22+
INSERT INTO user VALUES (3, 'Saul', 'M');
23+
INSERT INTO user VALUES (4, 'Norma', 'F');
24+
25+
INSERT INTO invoice VALUES (1, 'backery', 99,1);
26+
INSERT INTO invoice VALUES (2, 'meat', 88,1);
27+
INSERT INTO invoice VALUES (3, 'candy', 77,3);
28+
INSERT INTO invoice VALUES (4, 'soaps', 66,4);
29+
INSERT INTO invoice VALUES (5, 'meat', 55,2);
30+
INSERT INTO invoice VALUES (6, 'candy', 44,2);
31+
INSERT INTO invoice VALUES (7, 'soaps', 33,2);
32+
-- fetch some values
33+
SELECT user.name , COUNT(*) as count
34+
FROM user
35+
INNER JOIN invoice ON user.id = invoice.user_id
36+
GROUP BY user.id
37+
HAVING COUNT(*) > 1;

0 commit comments

Comments
 (0)