0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

自己結合

Posted at

テーブル情報
スクリーンショット 2020-10-29 23.04.10.png

カテゴリIDの違う商品をセット商品として商品名、金額をだす。

select
p1.name as 商品名1
,p2.name as 商品名2
,p1.price + p2.price as セット価格
from
products as p1
inner join
products as p2
on p1.id < p2.id 
and p1.category_id <> p2.category_id
order by p1.name

スクリーンショット 2020-10-29 23.34.36.png

on p1.id < p2.idとすることで1ど出現したレコードを出さないようにしている。(ぶどうみかんの組み合わせは表示されているがみかんぶどうの組み合わせは表示されていない)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?