SQL技术题: 相关表主要信息如下: 商品信息表[info_good]: 商品代码(Goodcode)、商品名称(Goodname)、规格(Goodtype)、进价(Goodpi)、售价(Goodpo) 进货入库明细表[jhrkmx]: 单号(billno)、日期(Xdate)、商品代码(Goodcode)、数量(Xquat)、单价(Xprice)、金额(money)、 1.查询出员工信息表[info_work]中,姓名(workname)中含有' 王'的所有员工信息 2.删除商品信息表[info_good]中,商品代码(Goodcode)相同的所有商品信息你能提供几种方法,并请写出其中种具体实现方法 3.查询出进货入库明细表[ jhrkmx]中入库单价大于商品信息中进价的所有入库明细,并显示商品名称,规格,售价. 4. 进货入库明细表[jhrkmx]中,请查出2011-04-01到2011-04-31所有入库信息中入库金额的排行(从大到小)的单据信息。 5. 进货入库明细表[hrkmx]中,请统计出211-01-01到211-04-31所有商品的入库汇总信息,即2011年4月份每个商品入库数量,金额汇总。
时间: 2023-06-03 21:07:13 浏览: 140
相关表及SQL代码
1. 查询语句:SELECT * FROM info_work WHERE workname LIKE "%王%"
2. 方法一:使用子查询删除重复的商品信息,再删除主表中相同商品代码的记录。具体实现:
DELETE FROM info_good
WHERE Goodcode IN
(SELECT Goodcode FROM
(SELECT Goodcode FROM info_good GROUP BY Goodcode HAVING count(Goodcode) > 1) AS a)
AND id NOT IN
(SELECT MIN(id) FROM info_good GROUP BY Goodcode HAVING count(Goodcode) > 1)
方法二:使用临时表,先将要删除的商品代码存储到临时表中,再将临时表中的商品代码与主表中删除。
具体实现:
CREATE TEMPORARY TABLE temp_table AS (SELECT Goodcode FROM info_good GROUP BY Goodcode HAVING COUNT(*) > 1);
DELETE FROM info_good WHERE Goodcode IN (SELECT Goodcode FROM temp_table);
DROP TEMPORARY TABLE temp_table;
3. 查询语句:SELECT info_good.Goodname, info_good.Goodtype, max(info_good.Goodpo), jhrkmx.Xprice
FROM jhrkmx
INNER JOIN info_good ON jhrkmx.Goodcode = info_good.Goodcode
WHERE jhrkmx.Xprice > info_good.Goodpi
GROUP BY info_good.Goodname, info_good.Goodtype, jhrkmx.Xprice
4. 查询语句:SELECT billno, SUM(money) AS total_money
FROM jhrkmx
WHERE Xdate >= '2011-04-01' AND Xdate <= '2011-04-31'
GROUP BY billno
ORDER BY total_money DESC
5. 查询语句:SELECT jhrkmx.Goodcode, info_good.Goodname, info_good.Goodtype,
SUM(jhrkmx.Xquat) AS total_quantity, SUM(jhrkmx.money) AS total_money
FROM jhrkmx
INNER JOIN info_good ON jhrkmx.Goodcode = info_good.Goodcode
WHERE Xdate >= '2011-01-01' AND Xdate <= '2011-04-31'
GROUP BY jhrkmx.Goodcode, info_good.Goodname, info_good.Goodtype
阅读全文