sqluername3 = "SELECT name_drug, mode, sum(quantity) As total_quantity FROM drug INNER JOIN mode ON drug.id_mode = mode.id_mode GROUP BY name_drug, mode HAVING(sum(quantity) <= 2) order by total_quantity "
SELECT A.name_drug,A.total_sale,B.total_quantity
FROM
(
SELECT name_drug, mode, sum(quantity) As total_quantity
FROM drug
INNER JOIN mode
ON drug.id_mode = mode.id_mode
GROUP BY name_drug, mode
HAVING(sum(quantity) <= 2)
) A
INNER JOIN
(
SELECT name_drug,sum(quantity_sale) as total_sale
FROM drug_sale
GROUP BY name_drug
) B
ON A.name_drug = B.name_drug
WHERE B.total_sale > A.total_quantity
select a.name_drug,sum(quantity) as qty,mode
from drug a,drug_sale b,mode c
where a.id_drug = b.id_drug and a.id_mode = c.id_mode
group by a.name,mode
having sum(b.quantity_sale) > sum(a. quantity)
Date :
2009-08-25 19:14:04
By :
superpheak
No. 5
Guest
คือ ตามที่คุณsuperpheak บอก ผมลองใช้ดู ค่า Sum ที่ได้ จะเกิน ตามตาราง คับ
เช่น
ในตาราง (ประมาณ)
drug - id_drug , name_drug , quantity , id_mode , lot
_________1_______aaa_________2________1_____ 1
_________2_______aaa_________1________1______2
select a.name_drug,sum(quantity) as qty,mode from drug as a,mode as b
where a.id_mode = b.id_mode
and a.id_drug = (select distinct id_drug from drug_sale where id_drug = a.id_drug group by id_drug having sum(quantity_sale) >= sum(a.quantity) )
Group By a.name_drug,mode
cmd.CommandText = "SELECT info_com(comID,IP_Address,Computer_Name,User_Login,location)" & _
",[เมนบอร์ด].[รหัส] as [รหัสเมนบอร์ด],[เมนบอร์ด].[รหัสอุปกรณ์_Serial] as [รหัสอุปกรณ์_Serialเมนบอร์ด],[เมนบอร์ด].Socket as [Socketเมนบอร์ด],[เมนบอร์ด].[ยี่ห้อ/รุ่น] as [ยี่ห้อ/รุ่นเมนบอร์ด] " & _
",cpu.[รหัส] as [รหัสซีพียู],cpu.[รหัสอุปกรณ์_Serial] as [รหัสอุปกรณ์_Serialซีพียู],cpu.[Socket] as [Socketซีพียู],cpu.[ยี่ห้อ/รุ่น] as [ยี่ห้อ/รุ่นซีพียู] " & _
",ram.[รหัส] as [รหัสแรม],ram.[รหัสอุปกรณ์_Serial] as [รหัสอุปกรณ์_Serialแรม],ram.[บัส],ram.[ยี่ห้อ/รุ่น] as [ยี่ห้อ/รุ่นแรม] " & _
",hdd.[รหัส] as [รหัสhdd],hdd.[รหัสอุปกรณ์_Serial] as [รหัสอุปกรณ์_Serialhdd],hdd.[ความจุ_GB],hdd.[ยี่ห้อ/รุ่น] as [ยี่ห้อ/รุ่นhdd] " & _
",vga.[รหัส] as [รหัสvga],vga.[รหัสอุปกรณ์_Serial] as [รหัสอุปกรณ์_Serialvga],vga.[ความจำ],vga.[ยี่ห้อ/รุ่น] as [ยี่ห้อ/รุ่นvga] " & _
",[power].[รหัส] as [รหัสpower],[power].[รหัสอุปกรณ์_Serial] as [รหัสอุปกรณ์_Serialpower],[power].[wat],[power].[ยี่ห้อ/รุ่น] as [ยี่ห้อ/รุ่นpower] " & _
" FROM info_com JOIN [เมนบอร์ด] on info_com.comID = [เมนบอร์ด].inforID" & _
",JOIN cpu on info_com.comID = cpu.inforID " & _
",JOIN ram on info_com.comID = ram.inforID " & _
",JOIN hdd on info_com.comID = hdd.inforID " & _
",JOIN vga on info_com.comID = vga.inforID " & _
",JOIN [power] on info_com.comID = [power].inforID" & _
" where info_com.comID = '" & id & "'" & _
" GROUP BY comID"