-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueries.sql
111 lines (93 loc) · 2.55 KB
/
Queries.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
-- 1
select *
from item;
-- 2
select *
from customer;
-- 3
select distinct category
from item;
-- 4
select *
from StoreProject.`Order`;
-- 5 -- hafte va mah okay nakardim
--select customerID, fName, lName, phoneNumber, ssn, userName, score
--from customer
--where customerID in (select customerID
-- From StoreProject.`Order`
-- WHERE )
order by score desc
limit 10;
-- 6 -- hafte va mah okay nakardim
select *
from item
order by score desc
limit 5;
-- 7
select itemID, name, currentPrice, category, offer
from item
where offer >= 15;
-- 8
select *
from item, supplier, supplier_supplies_item
where item.itemID = '1' -- given value
and supplier_supplies_item.Item_itemID = item.itemID
and supplier.supplierID = supplier_supplies_item.Supplier_supplierID;
-- 9
select *
from item, supplier, supplier_supplies_item
where item.itemID = '1' -- given value
and supplier_supplies_item.Item_itemID = item.itemID
and supplier.supplierID = supplier_supplies_item.Supplier_supplierID
order by item.currentPrice desc
limit 1;
-- 10
select distinct category
from item;
-- 11
SELECT *
from StoreProject.`Order`
where customerID = '1' -- [given value]
ORDER BY orderDate DESC
limit 10;
-- 12
SELECT comments.commentID, comments.title, comments.date, comments.text, comments.itemID, comments.customerID
FROM item
INNER JOIN comments ON comments.itemID = item.itemID
WHERE comments.itemID = '2'; -- [given itemID]
-- 13
SELECT comments.commentID, comments.title, comments.date, comments.text, comments.itemID, comments.customerID
FROM item
INNER JOIN comments ON comments.itemID = item.itemID
WHERE comments.itemID = '2' -- [given itemID]
order by comments.score desc
limit 3;
-- 14
SELECT comments.commentID, comments.title, comments.date, comments.text, comments.itemID, comments.customerID
FROM item
INNER JOIN comments ON comments.itemID = item.itemID
WHERE comments.itemID = '2' -- [given itemID]
order by comments.score asc
limit 3;
-- 15
SELECT sum(quantity)
FROM StoreProject.`Order_has_Item` rls
WHERE rls.Item_itemID = 1
and exists ( select *
FROM StoreProject.`Order` o
WHERE o.orderID = rls.Order_orderID
and o.status = "Done"
and month(o.orderDate) = 6 );
-- 16
select avg(totalPrice)
from StoreProject.`Order` o
where o.`status` = "Done";
-- 17
select * from StoreProject.Customer c
where exists ( select * from StoreProject.Addresses a
where a.customerID = c.customerID
and a.city = "Tehran");
-- 18
select *
from StoreProject.Supplier s
where s.address like "%Mashad%";