From b7cc478d11960babcbbd0dd685c82d1ee96582c3 Mon Sep 17 00:00:00 2001 From: Hamid Zehtab Date: Tue, 10 Jan 2023 22:28:52 +0330 Subject: [PATCH 1/4] Update views.py --- db_project/api/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db_project/api/views.py b/db_project/api/views.py index f0e0604..9656dd7 100644 --- a/db_project/api/views.py +++ b/db_project/api/views.py @@ -36,3 +36,5 @@ def list_of_products(request): return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + + From 598badc8e610f5fe84cd17ae9ca3774119ae92b8 Mon Sep 17 00:00:00 2001 From: Hamid Zehtab Date: Wed, 11 Jan 2023 13:03:35 +0330 Subject: [PATCH 2/4] new --- db_project/api/views.py | 294 ++++++++++++++++++++++++++++++++++++++++ phase3_queries.sql | 40 ++++++ 2 files changed, 334 insertions(+) diff --git a/db_project/api/views.py b/db_project/api/views.py index 9656dd7..c37268b 100644 --- a/db_project/api/views.py +++ b/db_project/api/views.py @@ -7,6 +7,26 @@ def get_projects(request): cursor.execute('SELECT * FROM tbl_cart;') projects = cursor.fetchall() cursor.execute('''SHOW columns FROM project.tbl_cart;''') +<<<<<<< HEAD + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + + +def list_of_products(request): + cursor = connection.cursor() + cursor.execute( + 'Select concat(b.title," Code ",a.Id) as list_doreh from tbl_doreh a left join tbl_reshteh b on a.id_reshteh = b.Id; ') + projects = cursor.fetchall() +<<<<<<< Updated upstream + cursor.execute('''SHOW columns FROM tbl_doreh;''') +======= +>>>>>>> 5e077d7a8938f3f44b82e64c6297857552f7b35d +======= + #cursor.execute('''SHOW columns FROM tbl_doreh;''') +>>>>>>> Stashed changes result = [] columns = [] for column in cursor.fetchall(): @@ -34,7 +54,281 @@ def list_of_products(request): # new_item.update({columns[i]: project[i]}) # result.append(new_item) + return render(request, 'clientarea.html', {'columns': ['list_doreh'], 'projects': projects}) + +<<<<<<< Updated upstream +def list_of_products(request): + cursor = connection.cursor() + cursor.execute('Select concat(b.title," Code ",a.Id) as list_doreh from tbl_doreh a left join tbl_reshteh b on a.id_reshteh = b.Id;') + projects = cursor.fetchall() + cursor.execute('''SHOW columns FROM tbl_doreh;''') +======= +>>>>>>> Stashed changes + +def list_of_users(request): + cursor = connection.cursor() + cursor.execute('Select concat(fname," ",lname) as names from tbl_users; ') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) +def list_of_product_types(request): + cursor = connection.cursor() + cursor.execute('Select title from tbl_reshteh; ') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + +def list_of_orders(request): + cursor = connection.cursor() + cursor.execute('Select d.Title,concat(b.fname," ",b.lname) as name,a.date_buy from tbl_buy_doreh a left join tbl_users b on a.id_username = b.username left join tbl_doreh c on a.id_doreh = c.Id left join tbl_reshteh d on d.Id = c.id_reshteh ; ') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + +def list_of_top_10_ussers_all(request): + cursor = connection.cursor() + cursor.execute('Select count(*) as num_buy, a.id_username , concat(b.fname," ",b.lname) as name from tbl_buy_doreh a left join tbl_users b on a.id_username = b.Id group by a.id_username order by count(*) desc Limit 10 ; ') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + + + +def change_users(): + + html = ''' +
+
+ " + "جست و جو کاربر +
+
+
+ + + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
''' + "سطح دسترسی" + "" + ''' +
+ +
+
+
+ + + +
+ +
+ '''; + +def list_of_top_10_users_month(request): + cursor = connection.cursor() + cursor.execute('Select count(*) as num_buy, a.id_username , concat(b.fname," ",b.lname) as name from tbl_buy_doreh a left join tbl_users b on a.id_username = b.Id where a.date_buy >= DATE(NOW() - INTERVAL 1 Month) group by a.id_username order by count(*) desc Limit 10 ;') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) +def list_of_top_10_users_week(request): + cursor = connection.cursor() + cursor.execute('Select count(*) as num_buy, a.id_username , concat(b.fname," ",b.lname) as name from tbl_buy_doreh a left join tbl_users b on a.id_username = b.Id where a.date_buy >= DATE(NOW() - INTERVAL 7 DAY) group by a.id_username order by count(*) desc Limit 10 ;') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + +def list_of_top_sold_product_week(request): + cursor = connection.cursor() + cursor.execute('Select count(*) as times_bought , c.Title from tbl_buy_doreh a left join tbl_doreh b on a.id_doreh = b.Id left join tbl_reshteh c on c.Id = b.id_reshteh where a.date_buy >= DATE(NOW() - INTERVAL 7 Day) group by a.id_doreh order by count(*) desc;') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + +def list_of_top_sold_procut_month(request): + cursor = connection.cursor() + cursor.execute('Select count(*) as times_bought , c.Title from tbl_buy_doreh a left join tbl_doreh b on a.id_doreh = b.Id left join tbl_reshteh c on c.Id = b.id_reshteh where a.date_buy >= DATE(NOW() - INTERVAL 1 Month) group by a.id_doreh order by count(*) desc; ') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + +def list_of_special_offers(request): + cursor = connection.cursor() + cursor.execute('Select c.title , a.discount2 as off_percentage from tbl_buy_doreh a left join tbl_doreh b on a.id_doreh = b.Id left join tbl_reshteh c on c.Id = b.id_reshteh where a.discount2 >= (a.fee*15/100);') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + +def list_of_providersof_product_admin(request): + cursor = connection.cursor() + cursor.execute('Select concat(a.Id," name ",c.title," offered by ",b.name) as offerd_by from tbl_doreh a left join tbl_institute b on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title;') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + +def list_of_providersof_product_admin_2(request): + cursor = connection.cursor() + cursor.execute('Select concat(a.Id," name ",c.title," offered by ",b.name) as offerd_by from tbl_institute b left join tbl_doreh a on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title where c.Id = '';') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) + +def list_of_cheapest_providerof_products_admin(request): + cursor = connection.cursor() + cursor.execute('Select concat(a.Id," name ",c.title," offered by ",b.name," for the cheapest price") as offerd_by from tbl_institute b left join tbl_doreh a on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title where c.Id = '' order by a.fee desc LIMIT 1;') + projects = cursor.fetchall() + #cursor.execute('''SHOW columns FROM tbl_doreh;''') + result = [] + columns = [] + for column in cursor.fetchall(): + columns.append(column[0]) + # for project in projects: + # new_item = dict() + # for i in range(len(columns)): + # new_item.update({columns[i]: project[i]}) + # result.append(new_item) + + return render(request, 'clientarea.html', {'columns': columns, 'projects': projects}) diff --git a/phase3_queries.sql b/phase3_queries.sql index 4e97409..f626fd7 100644 --- a/phase3_queries.sql +++ b/phase3_queries.sql @@ -25,11 +25,51 @@ Select count(*) as times_bought , c.Title from tbl_buy_doreh a left join tbl_dor # 6th query top sold products of month Select count(*) as times_bought , c.Title from tbl_buy_doreh a left join tbl_doreh b on a.id_doreh = b.Id left join tbl_reshteh c on c.Id = b.id_reshteh where a.date_buy >= DATE(NOW() - INTERVAL 1 Month) group by a.id_doreh order by count(*) desc; +# 7th query list of special offers (stuff with more than 15% off) Select c.title , a.discount2 as off_percentage from tbl_buy_doreh a left join tbl_doreh b on a.id_doreh = b.Id left join tbl_reshteh c on c.Id = b.id_reshteh where a.discount2 >= (a.fee*15/100); +# 8th query list of providers of a product for admin Select concat(a.Id," name ",c.title," offered by ",b.name) as offerd_by from tbl_doreh a left join tbl_institute b on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title; +# 9th query list of providers of a product for admin Select concat(a.Id," name ",c.title," offered by ",b.name) as offerd_by from tbl_institute b left join tbl_doreh a on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title where c.Id = ''; +# 9th query showing the cheapest provider of an item for admin Select concat(a.Id," name ",c.title," offered by ",b.name," for the cheapest price") as offerd_by from tbl_institute b left join tbl_doreh a on a.Id = b.id_doreh left join tbl_reshteh c on a.id_reshteh = c.Title where c.Id = '' order by a.fee desc LIMIT 1; +# 10th query list of last 10 orders of a user +#select * from tbl_buy_doreh a1 left join tbl_users a2 on a2.Id=a1.id_username order by a1.adate desc limit 10 +Select * from tbl_buy_doreh where id_username = 1 order by Id desc limit 10 ; +Select * from tbl_buy_doreh a left join tbl_users b on a.id_username = b.Id where a.id_username=1 order by a.date_buy desc limit 10; + +# 11th query list of comments for a given product +# select top 3 * from tbl_comments where id_buy_doreh=@v1 +CREATE TABLE `tbl_comment` ( + `Id` int(11) NOT NULL, + `comment` varchar(2000) DEFAULT NULL, + `id_username` int(20) DEFAULT NULL, + `score` int(20) DEFAULT NULL, + `id_doreh` int(20) DEFAULT NULL, + `adate` datetime default null, + PRIMARY KEY (`Id`), + Foreign Key (`id_username`) REFERENCES tbl_users(Id), + Foreign Key (`id_doreh`) REFERENCES tbl_doreh(Id) +); + +Select * from tbl_comments where id_buy_doreh = '' limit 3; + +# 12th query top 3 comments which gave the best score to product +select * from tbl_comments where id_buy_doreh=@v1 order by score limit 3; + +# 13th query top 3 comments which gave the worst score to product +select * from tbl_comments where id_buy_doreh=@v1 order by score desc limit 3; + +# 14th query showing the amount of sale of a product to admin +select Id,count(*) as buy_number from tbl_buy_doreh group by Id; + +# 15th query showing the average sale of store to admin +select avg(fee),month(date_buy),year(date_buy) from tbl_buy_doreh group by month(date_buy),year(date_buy); + +# 16th query providers of a given city +select * from tbl_users group by city; + From 9c8d58aa3319e9933dd5f50bd39ab8c51ae49bda Mon Sep 17 00:00:00 2001 From: Hamid Zehtab Date: Wed, 11 Jan 2023 13:03:41 +0330 Subject: [PATCH 3/4] a --- db_project/api/__pycache__/urls.cpython-310.pyc | Bin 572 -> 524 bytes .../api/__pycache__/views.cpython-310.pyc | Bin 810 -> 955 bytes .../users/__pycache__/urls.cpython-310.pyc | Bin 377 -> 377 bytes 3 files changed, 0 insertions(+), 0 deletions(-) diff --git a/db_project/api/__pycache__/urls.cpython-310.pyc b/db_project/api/__pycache__/urls.cpython-310.pyc index 3adf6bfbe85ea0f5193f25dcfcb18d20943a5b36..ff6d1ed70ece880b284f5fd7811253200ec226b5 100644 GIT binary patch delta 157 zcmdnP(!-*i&&$ij00dE+_9kCpWMFs<;vfSyAjbiSi)$uodsuR&aHVkcGN&^|aiwyl zvZk_UaRV_=3U@D)IRjjb7bwOD6HDOn#(MPie;Gulgmm^=(Tj3CIz!p8`LEPq7UB^Uu7 C_$c83 diff --git a/db_project/api/__pycache__/views.cpython-310.pyc b/db_project/api/__pycache__/views.cpython-310.pyc index 2d4a65fe9b5ff5bb056325918119510c792e0e66..116933d5a1c6f82ed0614044225b056060fdb8bd 100644 GIT binary patch delta 351 zcmZ3*wws+dpO=@50SLAfMxBLk4d3>0Ak zi!gyiCT^4tW|m|CF$<+iSZf$kSZY{mm{M5hFf}s=Gib8;Rfz|?`nWoWC}=6T1^N3b zlqBWECnpw_SXU_rd-#VdB~w^d|nwSKB+?yObk++rc^JHVD2!8QkS07jB5Cts-w;+FCg~^(X`AQ&l zMI1ol7F$tjacNFT5j&WZoS##go41moNNDmdMrWV__RNy9$&5fb7+?c3K-d|Gi&z*K zCbuy)*t3E-AkiXD5Wxo`gy4iQkabHSC$qRDK0htKpeR43G`XZ$3?wfKBE%+#GV4i+ RfSDiyp%cs!o;;UX4gh|FE)4(x diff --git a/db_project/users/__pycache__/urls.cpython-310.pyc b/db_project/users/__pycache__/urls.cpython-310.pyc index 5bd3716c7b5d00aaff89b364f1cfb087e409903a..5cba4bde4c10c3b1b33686c960a251b0a21b319d 100644 GIT binary patch delta 20 acmey#^plA@pO=@50SLA Date: Wed, 11 Jan 2023 13:30:47 +0330 Subject: [PATCH 4/4] Update phase3_queries.sql --- phase3_queries.sql | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phase3_queries.sql b/phase3_queries.sql index f626fd7..d080a35 100644 --- a/phase3_queries.sql +++ b/phase3_queries.sql @@ -70,6 +70,13 @@ select Id,count(*) as buy_number from tbl_buy_doreh group by Id; # 15th query showing the average sale of store to admin select avg(fee),month(date_buy),year(date_buy) from tbl_buy_doreh group by month(date_buy),year(date_buy); -# 16th query providers of a given city +# 16th query users of a given city select * from tbl_users group by city; + +# 17th query providers of a given city +alter table tbl_institute add column `city` varchar(20); +select * from tbl_institute group by city; + + +