查看最常见的5个外观 - python - sqlite

时间:2017-01-13 20:36:50

标签: python database sqlite e-commerce

我想通过我的数据库中的用户名找到我的前5位客户:

数据库代码是:

    BEGIN TRANSACTION;
CREATE TABLE "OrderHistory" (
    `Username`  TEXT,
    `ProductID` TEXT,
    `Category`  INTEGER,
    `Date`  TEXT,
    `Qty`   INTEGER,
    `ItemHistory`   TEXT,
    `TotalPrice`    INTEGER
);
INSERT INTO `OrderHistory` (Username,ProductID,Category,Date,Qty,ItemHistory,TotalPrice) VALUES 
     ('saqib','1',7,'2017-01-12',2,'Cookie',4),
     ('saqib','1',7,'2017-01-12',10,'Cookie',20),
     ('saqib','1',7,'2017-01-13',12,'Cookie',24),
     ('saqib','1',7,'2017-01-13',8,'Cookie',16),
     ('malik','1',7,'2017-01-13',5,'Cookie',10),
     ('malik','1',7,'2017-01-13',4,'Cookie',8),
     ('dex','1',7,'2017-01-13',7,'Cookie',14),
     ('olly','1',7,'2017-01-13',3,'Cookie',6),
     ('matt','1',7,'2017-01-13',9,'Cookie',18);
    COMMIT;

我想知道哪些客户购买的产品最多

这是简单的python和sqlite没有使用的框架

1 个答案:

答案 0 :(得分:0)

?

您可以在SQL Fiddle上进行测试:http://sqlfiddle.com/#!7/f6da2/1