我有这些表:
多迪亚
dhid INTEGER PRIMARY KEY NOT NULL,
dname TEXT NOT NULL,
dfname TEXT NOT NULL,
dage INTEGER NOT NULL,
dadd TEXT,
dphone INTEGER NOT NULL,
demail TEXT NOT NULL
数据
dtid INTEGER PRIMARY KEY NOT NULL,
ddate INTEGER NOT NULL,
dmonth INTEGER NOT NULL,
dyear INTEGER NOT NULL,
dmilk INTEGER NOT NULL,
dprice INTEGER NOT NULL default 35 ,
dmore TEXT,
ddhid INTEGER NOT NULL
价格牛奶
pid INTEGER PRIMARY KEY NOT NULL,
pmonth INTEGER NOT NULL,
pyear INTEGER NOT NULL,
milkprice INTEGER NOT NULL,
typeperson TEXT,
userid INTEGER,
gheeprice INTEGER,
defaultprice TEXT
现金数据
cashid INTEGER PRIMARY KEY NOT NULL,
cashdate INTEGER NOT NULL,
cashmonth INTEGER NOT NULL,
cashyear INTEGER NOT NULL,
cashamount INTEGER NOT NULL,
uid INTEGER NOT NULL,
utype TEXT NOT NULL,
cashtype TEXT NOT NULL,
cashmore TEXT
我想制作每月账单,我成功使用它购买了......但是在账单中我如何显示上个月的余额......我正在尝试使用它
SELECT
ddhid, dmonth, dyear, dmilk,
userid, pmonth, pyear, milkprice,
uid, cashmonth, cashyear, cashamount, utype,
SUM(dmilk) AS totalmilk,
SUM(dmilk*milkprice) AS totalamount,
SUM(cashamount) AS totalcash
FROM
doodhdata
LEFT JOIN pricemilk ON (
doodhdata.ddhid = pricemilk.userid
AND doodhdata.dmonth = pricemilk.pmonth
AND doodhdata.dyear = pricemilk.pyear
)
LEFT JOIN cashdata ON (
doodhdata.ddhid = cashdata.uid
AND doodhdata.dmonth = cashdata.cashmonth
AND doodhdata.dyear = cashdata.cashyear
)
WHERE
dmonth > '$mikdatem'
AND dyear='$mikdatey'
AND ddhid='$dhid'
但是我想在 milkprice 为 NULL 时使用 defaultprice ......怎么可能......?