首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

小菜,请问个SQL查询有关问题

2012-05-05 
小菜,请教个SQL查询问题产品表:products产品订单表:orders_products产品:products 表结构products_idprodu

小菜,请教个SQL查询问题
产品表:products
产品订单表:orders_products



产品:products 表结构

products_id products_title 

1 时尚长裙

2 时尚短裙



产品订单:orders_products表结构

orders_id products_id

1 1

2 1

3 2



需求:根据关键字(时尚)查询,并按产品热卖程度排序(统计订单表中产品进行排序)。

请问SQL要怎样写呢,亲们。


[解决办法]
select a.products_id,a.products_title,count(*) as num
from products A inner join orders_products B
on A.products_id = B.products_id where instr(a.products_title,'时尚')>0
group by a.products_id,a.products_title
order by num desc
[解决办法]

SQL code
select p.products_id  ,p.products_title  ,count(*) as numfrom products p,orders_products owhere p.products_id=o.products_idgroup by p.products_id  ,p.products_titleorder by 3 desc 

热点排行