我在 MySQL 中有一个名为 Bills 的表。
Bill item totalprice
BILL_1 Fossil Watch 9000
BILL_1 Fastrack 9000
BILL_1 Fastrack 9000
BILL_2 Woodlands 7000
BILL_2 Woodlands 7000
BILL_3 Denim Shirt 9000
BILL_3 Levis Jean 9000
SELECT 语句应返回如下所示
Bill item totalprice
BILL_1 Fossil Watch 9000
BILL_1 Fastrack -
BILL_1 Fastrack -
BILL_2 Woodlands 7000
BILL_2 Woodlands -
BILL_3 Denim Shirt 9000
BILL_3 Levis Jean -
The totalprice column is total bill amount.
最佳答案
不确定这是否是您真正想要的,但尝试一下:
select t.Bill, t.item, t.totalPrice
from (
select
b.Bill, b.item
,if(@price <> b.totalPrice or @price is null, b.totalPrice, '-') as totalPrice
,@price := b.totalPrice as dummy
from (select * from Bills order by totalPrice desc, item desc) b
cross join (select @price := null) t
) t
已编辑:
select t.Bill, t.item, t.totalPrice
from (
select
b.Bill, b.item
,if(@price <> b.totalPrice or @price is null, b.totalPrice, '-') as totalPrice
,@price := b.totalPrice as dummy
from (select * from Bills order by Bill, totalPrice desc) b
cross join (select @price := null) t
) t
关于java - MYSQL 中特定列中的重复项显示为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38735519/