我需要選擇一個列表,顯示每個已租用汽車的客戶的客戶編號,標題,名字和姓氏,按客戶姓氏的字母順序排列以及計數他們每個人的預訂都已放置。我需要幫助使用計數作爲查詢
我已經完成了第一部分,但不知道在哪裏放置預訂的數量。
下面是表是
create table customer
(customer_id char(4) primary key not null,
customer_sname varchar (30) not null,
customer_fname varchar (30) not null,
customer_title varchar (6) not null,
customer_address1 varchar (35) not null,
customer_address2 varchar (35) null,
customer_postcode varchar (25) null,
customer_phone varchar (30) null,
customer_email varchar (40) null,
customer_di varchar (40) not null)
ENGINE=InnoDB;
create table car_booking
(booking_id INTEGER AUTO_INCREMENT primary key not null,
car_id char (4) not null,
customer_id char (4) not null,
hire_sdate date not null,
hire_edate date not null)
engine=innodb
我已經這樣做了
select customer_id, customer_title, Customer_fname, customer_sname
from customer
where customer_id in
(select customer_id from car_booking)
order by customer_sname asc
感謝
我不使用此語法的唯一原因是它使用theta連接(即隱式連接)。 – 2010-07-04 00:21:55