0

私は次のようなビュー'view_type'を持っています:

type------name------fid

type_a----name1-----12
type_a----name2-----27
type_a----name3-----45
type_a----name4-----43
type_a----name5-----25
type_a----name7-----75
type_a----name6-----15

type_b----bame1-----12
type_b----bame2-----27
type_b----bame3-----45
type_b----bame4-----43
type_b----bame5-----25

type_c----came7-----55
type_c----came6-----25

ここで、名前フィールドに「ame」が含まれる結果をフェッチしたいのですが、「type_a」と「type_b」からのみであり、それぞれから4つの結果のみです。

type------name------fid

type_a----name1-----12
type_a----name2-----27
type_a----name3-----45
type_a----name4-----43
type_b----bame1-----12
type_b----bame2-----27
type_b----bame3-----45
type_b----bame4-----43

簡単に言うと、「groupby」の結果セットの結果を制限したいと思います。

'複雑なサブクエリ'または'ストアドプロシージャ'を使用しないでください。私を助ける簡単なクエリはありますか?

4

1 に答える 1

1

このクエリを試してください

select * from view_type where type = 'type_a' and name regexp 'ame' LIMIT 4
UNION
select * from view_type where type = 'type_b' and name regexp 'ame' LIMIT 4
于 2013-02-25T07:13:34.647 に答える