查看: 1157|回复: 4
|
这个database design行的通吗?
[复制链接]
|
|
我想得出total of [toyota] & [honda] 当 sales_record table的date等于23-11-05
如果根据以下的record....
total of toyota 应该是等于 [20]
total of honda 应该是等于 [15]
想请问下sql query该如何写?我这样的database design 又妥当吗?
这个是我的database design:
sales_record (table 1)
SRID
date
car_loan_record (table 2)
CLID
SRID
toyota
honda
car_sales_record (table 3)
CSID
SRID
toyota
honda
以下是3个table所含有的records
sales_record
SRID : SR10001
date : 23-11-05
SRID : SR10002
date : 23-11-05
car_loan_record
CRID : CR20001
SRID : SR10001
toyota : 5
honda : 4
CRID : CR20002
SRID : SR10002
toyota : 3
honda : 8
car_sales_record
CSID : CS20001
SRID : SR10001
toyota : 7
honda : 2
CSID : CS20002
SRID : SR10002
toyota : 5
honda : 1
[ 本帖最后由 一只优雅的猪 于 24-11-2005 02:32 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 24-11-2005 03:28 PM
|
显示全部楼层
你是指 sum(toyota) , sum(honda) 還是 sum( toyota + honda) ?? |
|
|
|
|
|
|
|
楼主 |
发表于 24-11-2005 03:59 PM
|
显示全部楼层
sum (toyata) , sum ( honda )
我刚改了我的database design.. 会比之前好吗?
如果这个design okie的话,那么sql query该怎么写才能得到sum (toyota), sum(honda)
我试写了。。。 如下:
SELECT COUNT (transaction_record.CAR_total)
FROM transaction_record INNER JOIN sales_record
ON transaction_record.SRID = sales_record.SRID
WHERE sales_record.date = '23-11-05'
AND transaction_record.RECORD_TYPE = 'LOAN' AND CAR_NAME = 'toyota'
- 所应得的result应该要是 17
- 注意!相同的SRID可以出现多次在transaction_record table里,那么用iNNER JOIN还可以吗?
新的database design
[sales_record] (table 1)
SRID
date
[transaction_record] (table 2)
TRID
SRID
CAR_NAME
CAR_TOTAL
RECORD_TYPE
data records in two tables
[sales_record]
SRID : SR10001
date : 23-11-05
SRID : SR10002
date : 23-11-05
[transaction_record]
TRID : TR20001
SRID : SR10001
CAR_NAME : toyota
CAR_TOTAL : 8
RECORD_TYPE : LOAN
TRID : TR20002
SRID : SR10001
CAR_NAME : toyota
CAR_TOTAL : 8
RECORD_TYPE : DEPOSIT
TRID : TR20003
SRID : SR10002
CAR_NAME : toyota
CAR_TOTAL : 9
RECORD_TYPE : LOAN
TRID : TR20004
SRID : SR10002
CAR_NAME : honda
CAR_TOTAL : 9
RECORD_TYPE : DEPOSIT |
|
|
|
|
|
|
|
发表于 14-12-2005 09:35 AM
|
显示全部楼层
your DB structure is fulfill your requirement but still not pro
and this is not a good DB desing
my advised is, 1 table for sale header table and 1 for sale detail table,1 for all transaction table,
sales header table store sale basic information like customer id,name adress,...
sales detail table store all the sale record like item,qty,price,eta(estimate arrive date)....
transaction table is used for store those sales transaction data no only sales transaction also can be others transaction, like purchase,purchase receipt,adjustment,DO....
请用中文发表
[ 本帖最后由 白日梦 于 14-12-2005 10:59 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 24-12-2005 04:03 PM
|
显示全部楼层
资料库有横行和直行设计。。。那要看如何运用。。而已~
睡觉的傻瓜。。。流着口水留言。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|