MYSQL查询 - 组合

时间:2015-10-01 03:42:16

标签: mysql nested-queries

我需要找到购买最贵产品的客户的名字和姓氏。

模式

订单

  • 的orderID
  • ordertypeID
  • 的customerID
  • 而purchaseDate

客户

  • 的customerID
  • 状态
  • 邮政编码
  • streetNumber
  • 的StreetAddress
  • customerLn
  • customerFn

Order_Contents

  • 的orderID
  • 的productID

产品

  • 的productID
  • 产品分类
  • 产品名称
  • 产品描述
  • UNITPRICE
  • 的inStock

我该如何撰写此查询?

3 个答案:

答案 0 :(得分:1)

您可以按如下方式使用子查询。

select 
   Customers.customerFN,
   Customers.customerLN
from
    Customers
    inner join Orders  on Orders.customerID = Customers.customerID
   inner join Order_Contents on Order_Contents.orderID = Orders.orderID 
where
    Order_Contents.productID in
    (select Products.productID from Products where Products.unitPrice = (select max(Products.unitPrice) from Products))

答案 1 :(得分:0)

像这样的东西似乎应该作为一个跳跃点(这里完全天真的方法)

MyModelC

答案 2 :(得分:0)

my $orig = q{
 1 cctataactt ggaatgtggg tggaggggtt catagttctc cctgagtgag acttgcctgc
61 ttctctggcc cctggtcctg tcctgttctc cagcatggtg tgtctgaagc tccctggagg
121 ctcctgcatg acagcgctga cagtgacact gatggtgctg agctccccac tggctttgtc
181 tggggacacc cgacgtaagt gcacattgcg ggtgctgagc tactatgggg tggggaaaat
0921 ggcctgaagt cccagcattg atggcagcgc ctcatcttca acttttgtgc tcccctttgc
10981 ctaaaccgta tggcctcccg tgcatctgta ttcaccctgt atgacaaaca cattacatta
11041 ttaaatgttt ctcaaagatg gagttaaa
};

## use this block if wish to extract each block
while ( $orig =~ /([atgc]{10})/simg )
{
  print "$1\n";
}

## or this block to get single string without numbers,spaces or newlines
$orig =~ s/[\d|\W]+//smg;
## or to retain newlines

print $orig;