diff --git a/db_project/api/__pycache__/urls.cpython-310.pyc b/db_project/api/__pycache__/urls.cpython-310.pyc index 3adf6bf..ff6d1ed 100644 Binary files a/db_project/api/__pycache__/urls.cpython-310.pyc and b/db_project/api/__pycache__/urls.cpython-310.pyc differ diff --git a/db_project/api/__pycache__/views.cpython-310.pyc b/db_project/api/__pycache__/views.cpython-310.pyc index 2d4a65f..116933d 100644 Binary files a/db_project/api/__pycache__/views.cpython-310.pyc and b/db_project/api/__pycache__/views.cpython-310.pyc differ diff --git a/db_project/api/views.py b/db_project/api/views.py index f0e0604..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,5 +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/db_project/users/__pycache__/urls.cpython-310.pyc b/db_project/users/__pycache__/urls.cpython-310.pyc index 5bd3716..5cba4bd 100644 Binary files a/db_project/users/__pycache__/urls.cpython-310.pyc and b/db_project/users/__pycache__/urls.cpython-310.pyc differ diff --git a/phase3_queries.sql b/phase3_queries.sql index 4e97409..d080a35 100644 --- a/phase3_queries.sql +++ b/phase3_queries.sql @@ -25,11 +25,58 @@ 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 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; + + +