需求是,在订单表的产品pro_id,有多少属于产品表ManageName_id= 5 业务员的,不知写的对吗,请教

代码之城 2017-05-13 10:42:11
一个sql 语句对吗?
需求是,在订单表的产品pro_id,有多少属于产品表ManageName_id= 5 业务员的,不知写的对吗,请教
select count(*) from taborder_product where pro_id in (select id from tabproduct where ManageName_id= 5 
...全文
629 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
小野马1209 2017-12-14
  • 打赏
  • 举报
回复
SQL语句按版主那样就没问题了
代码之城 2017-12-14
  • 打赏
  • 举报
回复
请教高手,还没解决呢
吉普赛的歌 2017-12-14
  • 打赏
  • 举报
回复
低于40分, 只能移到非技术区了, 抱歉
吉普赛的歌 2017-12-14
  • 打赏
  • 举报
回复
这已经不是 SQL Server 问题了, 帮你移到 asp 版块中
代码之城 2017-12-14
  • 打赏
  • 举报
回复
已经升级到 asp.net web form 了。 这些是老版本,必须要asp。请教大家
吉普赛的歌 2017-12-14
  • 打赏
  • 举报
回复
别搞asp老技术了, 升级到 asp.net mvc , 至少用 asp.net web form 吧
代码之城 2017-12-14
  • 打赏
  • 举报
回复
是的 , 我测试了,数据库中没问题, 但是asp出来是空的
代码之城 2017-05-14
  • 打赏
  • 举报
回复
有会asp的吗,看看我的asp代码有错误吗
代码之城 2017-05-13
  • 打赏
  • 举报
回复
整个代码,是不是执行两次conn.execute原因,是不是需要关闭
<tr class="TR" height="18">
							<td align="left"> 产品个数</td>
							<td width="70%"> 
							<%
							dim sum
							sum=conn.execute("select count(*) from tabproduct where ManageName_id= " & Session("ManageName_id") & "")
							response.Write(sum(0))
							
							%>
							个产品量(通常加100个产品,会每月出一单)
							
							</td>
						</tr>
 <tr class="TR" height="18">
							<td align="left"> 订单个数</td>
							<td> 
                            <%
							dim order_sum_sql
							'ss="select count(pro_id) from taborder_product where pro_id in (select id from tabproduct where ManageName_id= " & Session("ManageName_id")
							
							'order_sum_sql=conn.execute(ss)
	order_sum_sql=conn.execute("select count(pro_id) from taborder_product where pro_id in (select id from tabproduct where ManageName_id= " & Session("ManageName_id") & "")
							
							'response.Write ss
							response.Write order_sum_sql(0)
							%>
                            个
                            </td>
						</tr>
二月十六 2017-05-13
  • 打赏
  • 举报
回复
引用 7 楼 Jamie2012 的回复:
数据库中执行sql语句是对的 结果是2 ,在asp页面是空,难道asp写错了吗,请指教
写个string sql = '查询语句'然后 order_sum=conn.execute(sql) 打个断点看看这个sql字符串是不是和刚才执行的一样
代码之城 2017-05-13
  • 打赏
  • 举报
回复
数据库中执行sql语句是对的 结果是2 ,在asp页面是空,难道asp写错了吗,请指教
代码之城 2017-05-13
  • 打赏
  • 举报
回复
我是asp 页面程序。不知哪里错了
二月十六 2017-05-13
  • 打赏
  • 举报
回复
引用 4 楼 Jamie2012 的回复:
order_sum=conn.execute("select count(pro_id) from taborder_product where pro_id in (select id from tabproduct where ManageName_id= " & Session("ManageName_id") & "") response.Write(order_sum(0)) 出来是空的啊, 正确应该是1,哪里错了
直接在数据库里执行这句有数据吗?
SELECT  COUNT(DISTINCT pro_id)
FROM    taborder_product
WHERE   pro_id IN ( SELECT  id
                    FROM    tabproduct
                    WHERE   ManageName_id = 5 )
代码之城 2017-05-13
  • 打赏
  • 举报
回复
order_sum=conn.execute("select count(pro_id) from taborder_product where pro_id in (select id from tabproduct where ManageName_id= " & Session("ManageName_id") & "") response.Write(order_sum(0)) 出来是空的啊, 正确应该是1,哪里错了
二月十六 2017-05-13
  • 打赏
  • 举报
回复
引用 2 楼 Jamie2012 的回复:
我描述错了 ,重新说一下, 表A是 订单产品表,里面是3000个订单产品,表B是产品表 ,有5000个产品,有5个业务员加的,现在想知道业务员5 卖出多少个产品数量
就我说的那个例子。如果两个订单是同一个产品的话,楼主想要搜索出来是2,那么楼主的语句应该没问题,如果想要的结果是1,就用一楼那个语句试试
代码之城 2017-05-13
  • 打赏
  • 举报
回复
我描述错了 ,重新说一下, 表A是 订单产品表,里面是3000个订单产品,表B是产品表 ,有5000个产品,有5个业务员加的,现在想知道业务员5 卖出多少个产品数量
二月十六 2017-05-13
  • 打赏
  • 举报
回复
楼主这样搜索,搜出来的应该是产品id是业务员5的所有订单数量。比如两个订单买了同样的一个产品,这时候搜索出来的是2,楼主想要的结果应该是1吧?试试这个:
SELECT  COUNT(DISTINCT pro_id)
FROM    taborder_product
WHERE   pro_id IN ( SELECT  id
                    FROM    tabproduct
                    WHERE   ManageName_id = 5 )
qiuyongaaa 2017-05-13
  • 打赏
  • 举报
回复
引用 2 楼 Jamie2012 的回复:
我描述错了 ,重新说一下, 表A是 订单产品表,里面是3000个订单产品,表B是产品表 ,有5000个产品,有5个业务员加的,现在想知道业务员5 卖出多少个产品数量
你的业务员(manage_id)出现在哪个表??表A还是表B?想知道业务员卖出多少是统计那张表?订单?
二月十六 2017-05-13
  • 打赏
  • 举报
回复
建议楼主到asp版问问
二月十六 2017-05-13
  • 打赏
  • 举报
回复
引用 9 楼 Jamie2012 的回复:
整个代码,是不是执行两次conn.execute原因,是不是需要关闭
<tr class="TR" height="18">
							<td align="left"> 产品个数</td>
							<td width="70%"> 
							<%
							dim sum
							sum=conn.execute("select count(*) from tabproduct where ManageName_id= " & Session("ManageName_id") & "")
							response.Write(sum(0))
							
							%>
							个产品量(通常加100个产品,会每月出一单)
							
							</td>
						</tr>
 <tr class="TR" height="18">
							<td align="left"> 订单个数</td>
							<td> 
                            <%
							dim order_sum_sql
							'ss="select count(pro_id) from taborder_product where pro_id in (select id from tabproduct where ManageName_id= " & Session("ManageName_id")
							
							'order_sum_sql=conn.execute(ss)
	order_sum_sql=conn.execute("select count(pro_id) from taborder_product where pro_id in (select id from tabproduct where ManageName_id= " & Session("ManageName_id") & "")
							
							'response.Write ss
							response.Write order_sum_sql(0)
							%>
                            个
                            </td>
						</tr>
sqlite代码还行,asp代码我不太懂。。。

2,099

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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