Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. import mysql.connector
  2. try:
  3. cnx = mysql.connector.connect(host='localhost',database='checklist',user='root',password='')
  4. cursor = cnx.cursor()
  5. except:
  6. print("There is no connection with server")
  7. raise SystemExit()
  8.  
  9. print(" Analysis of checks")
  10. print(" MENU")
  11. print("1: Top 10 products by turnover, number of sales, the number of checks")
  12. print("2: Number of checks in the shop")
  13. print("3: Number of checks certain product")
  14. print("4: The average check of certain products")
  15. print("5: The turnover, number of checks, sales in shops")
  16. print("6: Number of checks on certain product by day the of week")
  17. print("7: Number of checks on certain product by dayS the of week")
  18. print("0: Exit")
  19.  
  20. while (True):
  21.  
  22. n = int(input("Input number of query\n"))
  23. if (n==1):
  24. query = ("SELECT product__name, total_price * COUNT( product_id)FROM products GROUP BY product_id ORDER BY (total_price * COUNT( product_id )) DESC LIMIT 0 , 10")
  25. cursor.execute(query)
  26. result = cursor.fetchall()
  27. print("Top 10 products by turnover")
  28. for i in result:
  29. print(i)
  30. query =("SELECT product__name, qty*COUNT( product__name) FROM products GROUP BY product_id ORDER BY (qty*COUNT( product__name )) DESC LIMIT 0 , 10 ")
  31. cursor.execute(query)
  32. result = cursor.fetchall()
  33. print("Top 10 products by number of sales")
  34. for i in result:
  35. print(i)
  36. query = ("SELECT product__name,COUNT( product__name ) FROM products GROUP BY product_id ORDER BY COUNT(product__name) DESC LIMIT 0,10 ")
  37. cursor.execute(query)
  38. result = cursor.fetchall()
  39. print("Top 10 products by number of checks")
  40. for i in result:
  41. print(i)
  42.  
  43. elif n==2:
  44. shopname = input("Enter Shop Name, for example Shop №01\n")
  45. query = ("SELECT shop__name, COUNT( shop_id ) FROM checkinfo WHERE (shop__name='%s') GROUP BY shop_id ORDER BY (COUNT( shop_id )) DESC")%shopname
  46. print("Number of checks in the shop")
  47. cursor.execute(query)
  48. result = cursor.fetchall()
  49. print(result)
  50.  
  51. elif n==3:
  52. productname = input("Enter product, for example, Kent Nanotek Silver 2.0\n")
  53. query = ("SELECT product__name, COUNT( product__name )FROM products WHERE (product__name ='%s')ORDER BY COUNT( product_id ) DESC ")%productname
  54. print("Number of checks certain product")
  55. cursor.execute(query)
  56. result = cursor.fetchall()
  57. print(result)
  58.  
  59. elif n==4:
  60. productname = input("Enter product, for example, Kent Nanotek Silver 2.0\n")
  61. query = ("SELECT product__name, SUM( checkinfo.total_price )/COUNT( products.product__name ) FROM products, checkinfo WHERE (product__name ='%s' AND checkinfo.id = products.id)")%productname
  62. print("The average check of certain products")
  63. cursor.execute(query)
  64. result = cursor.fetchall()
  65. print(result)
  66. elif n==5:
  67. query = ("SELECT shop__name, SUM( total_price ) FROM checkinfo GROUP BY shop__name ")
  68. cursor.execute(query)
  69. result = cursor.fetchall()
  70. print("The turnover of the shops")
  71. for i in result:
  72. print(i)
  73. query =("SELECT shop__name, COUNT( shop_id ) FROM checkinfo GROUP BY shop_id ORDER BY ( COUNT( shop_id ) ) DESC ")
  74. cursor.execute(query)
  75. result = cursor.fetchall()
  76. print("Number of checks in the shops")
  77. for i in result:
  78. print(i)
  79. query = ("SELECT shop__name, SUM( items_qty ) FROM checkinfo GROUP BY shop_id ORDER BY ( COUNT( items_qty ) ) DESC ")
  80. cursor.execute(query)
  81. result = cursor.fetchall()
  82. print("Sales in the shops")
  83. for i in result:
  84. print(i)
  85. elif n==6:
  86. day = input("Enter day of the week: 0:Monday .. 6:Sunday\n")
  87. productname = input("Enter product, for example, Kent Nanotek Silver 2.0\n")
  88. query = ("SELECT product__name, COUNT(product__name)FROM products,checkinfo WHERE (product__name='%s' AND checkinfo.week_day= '%s' AND products.id = checkinfo.id)")%(productname,day)
  89. print("Number of checks on certain product by day the of week")
  90. cursor.execute(query)
  91. result = cursor.fetchall()
  92. print(result)
  93. elif n==7:
  94. productname = input("Enter product, for example, Kent Nanotek Silver 2.0\n")
  95. query = ("SELECT week_day, COUNT( product__name ) FROM products, checkinfo WHERE (product__name = '%s' AND products.id = checkinfo.id)GROUP BY (week_day)")%productname
  96. print("Number of checks on certain product by dayS the of week: 0:Monday .. 6:Sunday")
  97. cursor.execute(query)
  98. result = cursor.fetchall()
  99. for i in result:
  100. print(i)
  101.  
  102. elif n==0:
  103. print("Good bye!")
  104. break
  105. raise SystemExit()
  106. cursor.close()
  107. cnx.close()
  108.  
  109. elif n not in [0,1,2,3,4,5,6,7]:
  110. print("This command does not exist")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement