.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

ถามเกี่ยวกับคำสั่ง SQL คับ Options · View
zerozaaa
Posted: Monday, July 28, 2008 1:09:08 AM
Rank: มือพระกาฬ
Groups: Member

Joined: 6/13/2008
Posts: 79

ใน 1 ตาราง เราสามารถ คูณค่าใน column 2 column แล้ว โชว์ลงอีก column ได้ไหมคับ

อย่างค่า table column เป็นค่าของราคา อีก column เป็น จำนวนสินค้า ต้องการให้ column ทั้ง2 colume คูณกัน ในแต่ล่ะแถว ทำอย่างไหรคับถามผู้รู้ที

ผมคิดไม่ออกจิงๆๆจะทำไงคับ

nottp
Posted: Tuesday, July 29, 2008 7:23:07 AM

Rank: มือพระกาฬ
Groups: Member

Joined: 12/2/2007
Posts: 49
Location: Thai

zerozaaa wrote:

ใน 1 ตาราง เราสามารถ คูณค่าใน column 2 column แล้ว โชว์ลงอีก column ได้ไหมคับ

อย่างค่า table column เป็นค่าของราคา อีก column เป็น จำนวนสินค้า ต้องการให้ column ทั้ง2 colume คูณกัน ในแต่ล่ะแถว ทำอย่างไหรคับถามผู้รู้ที

ผมคิดไม่ออกจิงๆๆจะทำไงคับ

คูณกันในที่นี้คือลิงค์กัน(Join)หรือเปล่าครับ ถ้าจะให้ tbl Joinกันโดยพื้นฐานทำแบบนี้ครับ

Select oid, tbl_customer.cid, cname
From order_tbl, customer_tbl
Where order_tbl.cid = customer_tbl.cid

ประมาณนี้ครับ



I Love .NET
ngo_somc
Posted: Tuesday, July 29, 2008 2:12:38 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 7/7/2008
Posts: 9
Location: Thai

ลองทำแบบนี้ดูนะครับ  ไม่แน่ใจนะครับ

select price,quantity,(price * quantity) as mix from production group by price,quantity

ngo_somc
Posted: Tuesday, July 29, 2008 2:13:36 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 7/7/2008
Posts: 9
Location: Thai

โทษทีครับ      ไม่ต้อง group by นะครับ

อิอิ

zerozaaa
Posted: Tuesday, July 29, 2008 5:54:46 PM
Rank: มือพระกาฬ
Groups: Member

Joined: 6/13/2008
Posts: 79

 sqlselect = "SELECT account.id_product, SUM(account.amount), account.price, SUM(account.mix),product.name_product  FROM account,product    WHERE account.date = '" + Calendar2.SelectedDate.ToString("d/MM/yyyy") +"' GROUP BY account.id_product,account.price";

คือว่า ชุดนี้ มัน SELECT โดยที่ให้ Row แต่ล่ะวัน(calendar2.selectdeDate) จะรวมกัน โดยแบ่งตาม กลุ่มของ account.id_product  และต้องการ อีกคืออยากให้มี column ของ product.name_product ซึ่ง อยู่คนล่ะ table ให้มาแสดง ด้วยคับ (product.name_product) ลงไปโชว์ใน Gridview ผมทำแล้ว มันไม่ได้คับ มันError 

ช่วยดูทีคับ

 

zerozaaa
Posted: Friday, August 01, 2008 12:14:40 AM
Rank: มือพระกาฬ
Groups: Member

Joined: 6/13/2008
Posts: 79

(account.amount * account.price) ลองดูแล้วคับ มันฟ้อง {"Incorrect syntax near '*'."} คับ

Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by