&&&&&&&&&&&&&&一个简单的SQL语句问题&&&&&&&&&&&& 早上结帐

LWWL 2004-03-15 09:08:54
我想加个单位这个字段但又不能按单位分组, 我是这样加的(肯定报错):
select a.id,b.供应商,b.名称,b.规格,b.单位
,数量=sum(b.数量*a.数量),总价=sum(b.数量*b.单价)
,合计=sum(a.数量*b.数量*b.单价)
into tmp
from tcg_idx a
join tcg b on a.id=b.idx
join tcg_main c on b.idmain=c.id
where b.idmain=1
group by a.id,b.供应商,b.名称,b.规格
怎么做?
如何把上面查询出的结果插入到1个TMP表中?
...全文
72 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
LWWL 2004-03-15
  • 打赏
  • 举报
回复
insert into tmp
select a.id as idx,b.供应商,b.名称,b.规格,单位=max(b.单位),b.单价
,数量=sum(b.数量*a.数量),总价=sum(b.数量*b.单价)
,合计=sum(a.数量*b.数量*b.单价)
from tcg_idx a
join tcg b on a.id=b.idx
join tcg_main c on b.idmain=c.id
where b.idmain=@h
group by a.id,b.供应商,b.名称,b.规格,b.单价
报错:仅当使用了列的列表,并且IDENTITY_INSERT为ON时,才能在表'tmp'中为标识列指定显示值
tmp 字段:
id(自增的,int) idx(int) 供应商 名称 规格 单价 单位 数量 总价
midnight2002 2004-03-15
  • 打赏
  • 举报
回复
select * into table_a from table_b 是从表a查询插入b表,适用于b表不存在,要生成b表的情况。
insert into table_b select * from table_a 适用于将a表查询到的数据插入b表。
realgz 2004-03-15
  • 打赏
  • 举报
回复
insert into tmp select …… from 吗
如果语句是动态生成的就
insert into tmp exec (@exec)
victorycyz 2004-03-15
  • 打赏
  • 举报
回复

插入数据用insert into table select ....的语法格式。

你能不能把你的问题重新完整地贴一下?
leeboyan 2004-03-15
  • 打赏
  • 举报
回复
insert into tmp +你的那一堆
LWWL 2004-03-15
  • 打赏
  • 举报
回复
我说错了 大哥
那个TMP是我建立的1个表 表里面都有字段 INTO的话肯定是先删除后建立,我不想这样而是直接插入怎做?
realgz 2004-03-15
  • 打赏
  • 举报
回复
或者是还有什么其他需求?
realgz 2004-03-15
  • 打赏
  • 举报
回复
select a.id,b.供应商,b.名称,b.规格,单位=max(b.单位)
,数量=sum(b.数量*a.数量),总价=sum(b.数量*b.单价)
,合计=sum(a.数量*b.数量*b.单价)
into tmp
from tcg_idx a
join tcg b on a.id=b.idx
join tcg_main c on b.idmain=c.id
where b.idmain=1
group by a.id,b.供应商,b.名称,b.规格
--有问题吗?
/*****************************************************************************************/#include #include #include #include //输入/输出文件流类using namespace std;const int Maxr=100;//最多的读者const int Maxb=100;//最多的图书const int Maxbor=5;//每位读者最多借五本书//读者类,实现对读者的信息的描述class Reader { private: int tag; //删除标记 1:已删 0:未删 int no; //读者编号 char name[10]; //读者姓名 int borbook[Maxbor];//所借图书 public: Reader() {} char *getname() {return name;} //获取姓名 int gettag() {return tag;} //获取删除标记 int getno() {return no;} //获取读者编号 void setname(char na[]) //设置姓名 { strcpy(name,na); } void delbook(){ tag=1; }//设置删除标记 1:已删 0:未删 void addreader(int n,char *na)//增加读者 { tag=0; no=n; strcpy(name,na); for(int i=0;i一个输入文件 while (1) { file.read((char *)&s,sizeof(s)); if (!file)break; top++; read[top]=s; } file.close(); //关闭 reader.txt } void clear()//删除所有读者信息 { top=-1; } int addreader(int n,char *na)//添加读者时先查找是否存在 { Reader *p=query(n); if (p==NULL) { top++; read[top].addreader(n,na); return 1; } return 0; } Reader *query(int readerid)//按编号查找 { for (int i=0;i<=top;i++) if (read[i].getno()==readerid && read[i].gettag()==0) { return &read[i]; } return NULL; } void disp() //输出所有读者信息 { for (int i=0;i<=top;i++) read[i].disp(); } void readerdata();//读者库维护 ~RDatabase() //析构函数,将read[]写到reader.txt文件中 { fstream file("reader.
本帖最后由 hhmxxx 于 2012 7 18 20:51 编辑 惠普实验室曾经有一个Ocr引擎 支持中文的识别 这个库叫tesseract ocr 最新版本是3 01 库的源码在这里下载:http: code google com p tesseract ocr downloads list ExcelHome 网友把这个库封装成了一个进程外Com服务器 可以在Excel或者Word或者IE或者其他支持Com技术的程序中调用(32位或者64位的Excel Word都可以调用) 首先下载我的封装库 安装MyOcrServer v100 exe 安装完成后可以这样在Excel中使用 Dim FMyFuns As Object Dim MyStr As String Set FMyFuns CreateObject "MyOcrServer MyOcrServerCom" MyStr FMyFuns TsOcr "E: test jpg" "3" "3" "0" "chi sim" MsgBox MyStr Set FMyFuns Nothing 参数说明:第一个为文件名 第二个为引擎模式EngineMode emTesseractOnly emCubeOnly emCombined emDefault ;第一个为0 依此类推 第三个为PageSegmentation psOSDOnly psAutoOSD psAutoOnly psAuto psSingleColumn psSingleVerticalBlock psSingleBlock psSingleLine psSingleWord psCircleWord psSingleChar ; 第四个为PixelFormat piAuto pi8bit pi24bit pi32bit ; 第五个为识别使用的语言模块 比如英文"eng" 中文"chi sim" 有兴趣的可以去试试 ">本帖最后由 hhmxxx 于 2012 7 18 20:51 编辑 惠普实验室曾经有一个Ocr引擎 支持中文的识别 这个库叫tesseract ocr 最新版本是3 01 库的源码在这里下载:http: code google com p tesseract ocr downloads list ExcelHome 网友把这个库封装成了一个 [更多]

22,298

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧