select b.brand,b.title,b.price from tb_item b where (select count(DISTINCT a.price) from tb_item a where b.brand = a.brand and b.price<=a.price)<=3 and b.brand is not null order by b.brand,b.price desc;
表结构是这样的: mysql> desc tb_item; +------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+----------------+ | id | bigint(20) | NO | PRI | NULL | auto_increment | | cid | bigint(20) | NO | MUL | NULL | | | brand | varchar(50) | YES | | NULL | | | model | varchar(50) | YES | | NULL | | | title | varchar(100) | YES | | NULL | | | sell_point | varchar(500) | YES | | NULL | | | price | bigint(20) | YES | | NULL | | | num | int(11) | YES | | NULL | | | barcode | varchar(30) | YES | | NULL | | | image | varchar(500) | YES | | NULL | | | status | tinyint(4) | YES | | 2 | | | created | datetime | YES | | NULL | | | updated | datetime | YES | | NULL | | +------------+--------------+------+-----+---------+----------------+ 13 rows in set (0.00 sec)
1
megachweng 2017-10-15 22:13:21 +08:00 via iPhone 1
楼主可以考虑用 markdown 稍微拍一下版,连在一起就算有大佬知道,估计也没心情回复
|
2
dongxinb 2017-10-15 23:00:48 +08:00
粗粗看了一眼,好像是:
将每个牌子的商品的价格放到一个 set 里面,然后取出前三大的。然后再输出这前三大的价格对应的商品牌子、名称、价格。 |
3
vexe 2017-10-15 23:18:55 +08:00
不会 markdown,可以贴到 gist
|
4
flyingghost 2017-10-16 11:39:26 +08:00
|
5
kylesean 2017-10-16 12:52:27 +08:00
兄弟,不行你截图啊。整这么费劲,看得人也费劲
|
6
noNOno 2017-10-16 13:17:20 +08:00
查询降价三次以下的品牌的 brand,title,price,按 brand,price desc 排序
业务逻辑是这个么 |
7
bxb100 2017-10-16 14:47:26 +08:00
https://gist.github.com/bxb100/df6d3afe1d3b0df93be347875fd75fbd
是查询一个牌子最高 3 个价格的信息吧 |
8
scriptish 2017-10-16 16:27:48 +08:00
b.price<=a.price 这个语句可以怎么解释?
|