Я думаю, что библиотека curses может помочь.
import curses
import datetime
stdscr = curses.initscr()
curses.noecho()
stdscr.nodelay(1) # set getch() non-blocking
stdscr.addstr(0,0,"Press \"p\" to show count, \"q\" to exit...")
line = 1
try:
while 1:
c = stdscr.getch()
if c == ord('p'):
stdscr.addstr(line,0,"Some text here")
line += 1
elif c == ord('q'): break
"""
Do more things
"""
finally:
curses.endwin()
Если вы объясните, какой заказ клиента вы хотите и хотите ли вы указывать полную цену заказа или цену каждого товара в этом заказе, мы можем указать более конкретно. Я должен был сделать некоторые предположения (см. Комментарии):
select
c.Company
, o.ShipDate as this_is_max_ship_date_of_customer
, o.OrderID --Added OrderID so you know what the price is associated with
, sum(oi.price) this_is_sum_of_prices_of_the_order
--if you want the price of a particular item, you can add ItemID beneath OrderID and also group by it
from dbo.Customers c
join dbo.Orders o
on c.CustomerID = o.CustomerID
join dbo.OrderItems oi
on o.OrderID = oi.OrderID
where o.Deleted = 0
and o.ShipDate in (select max(inner_o.ShipDate) from dbo.Orders inner_o
where inner_o.Company = c.Company
group by inner_o.Company)
--This subquery points to the outer reference - a useful trick
-- it means only the most recent ShipDate for the customer is shown
and o.OrderId in (select max(inner_o2.OrderId) from dbo.Orders inner_o2
where inner_o2.Company = c.Company
and inner_o2.ShipDate = o.ShipDate
group by inner_o2.Company)
--This subquery is doing the same thing, but for your OrderId
--Unfortunately you don't specify enough in your question, so
-- I have to assume you only want their most recent order
--To prevent an ShipDate that is not of the OrderId you care about,
-- I had to add the second where clause here
group by
c.Company,
o.ShipDate,
o.OrderId
Вам нужно решить, как вы хотите объединить все разные цены на заказы для компании. Я не знаю, чего ты хочешь. Например, следующее возвращает сумму всех цен:
SELECT c.Company, MAX(o.ShipDate) AS Latest_ShipDate,
SUM(oi.Price) AS sum_Price
FROM dbo.Customers c JOIN
dbo.Orders o
ON c.CustomerID = o.CustomerID JOIN
dbo.OrderItems oi
ON o.OrderID = oi.OrderID
WHERE o.Deleted = 0
GROUP BY oi.InvMasID, c.Company