m**********2 发帖数: 2252 | 1 有个table,有3个columns。一个是客户ID,一个orderID,一个orderdate。每一个
order就有一个orderID。比如客户ID 500,会有orderID 201,302,809. 客户ID 600
,会有orderID 211,298,344。
现在我想在这个table加一个column,ordersequenceID,比如客户ID 500,根据
orderID的大小,如果orderID是201,就是1,orderID是302,就是2,orderID是809,就
是3. 同样,比如比如客户ID 600,根据orderID的大小,如果orderID是211,就是1,
orderID是298,就是2,orderID是344,就是3。
这个应该怎样做?
谢谢。 |
|
B*****g 发帖数: 34098 | 2 should be sql server as table name is [Order]
But when I count ( and ), there are 2 ( and 3 ), can not believe it can
compile.
SELECT
OrderID
, CustomerName
, RowNumber =
(SELECT COUNT(*)
FROM [Order] b
WHERE b.OrderID = a.OrderID
AND b.ProductID < a.ProductID)
FROM [Order] a)
GROUP BY OrderID
ORDER BY OrderID |
|
P********R 发帖数: 1691 | 3 Oracle trigger procedure中生成的数据如何送到stored procedure中?
表orderitems有四列:orderid, detail, partid, qty.
比如在主程序中接收三个变量:
v_Orderid ORDERS.orderid%TYPE := &2;
v_Partid INVENTORY.partid%TYPE := &3;
v_Qty ORDERITEMS.qty%TYPE := &4;
然后用:
AddLineItemSP(v_Orderid, v_Partid, v_Qty);
语句激活stored procedure并将三个值赋给i_Orderid, i_partid, i_Qty:
CREATE OR REPLACE PROCEDURE AddLineItemSP (
i_Orderid IN ORDERITEMS.orderid %TYPE,
i_Partid IN ORDERITEMS.partid %TYPE,
i_Qt... 阅读全帖 |
|
s******e 发帖数: 285 | 4 这个和第一个表根本没关系啊
SELECT orderid, count(*) AS freq
FROM order
GROUP BY orderid
ORDER BY orderid |
|
b*****e 发帖数: 364 | 5 SELECT a.ID, a.ORDERID, MIN(a.orderdate-b.orderdate) as DateDifference,
COUNT(b.orderID)+1 as OrderSequence
FROM Table a
JOIN Table b
ON a.ID=b.ID
WHERE a.orderdate>b.orderDate
GROUP BY a.ID, a.ORDERID; |
|
q*c 发帖数: 9453 | 6 终于放假了, 你们这些单机党也太猖獗了。 有点时间给你们个堆机器版的。 不过时
间很少所以剩余的自己脑补。
老魏你说的能达到你的单机版的 1/10 就了得了,你的也就几M/s. 你看看我这个版本。
用的全是 proven technology. 有点经验的一看就知道肯定能 work. 全套卖票。
当然你也说了, 我这个酒不需要实现了, 因为比较麻烦。 不过你看看就知道肯定无
问题
实现的和你那个功能完全一样。
前段, 无状态的 web server. 接受订票. 受到订票直接转到相应的中间集群。
中间, 是按照用户 id hash 的 用户数据库群 + 用户 controller.
收到订单然后在数据库中产生该用户的订票信息. 比如有三张连票,
userid, orderID, start1, end1, status = processing
userid, orderID, start2, end2, status = processing
userid, orderID, start3, end3, status = processing
后端, 是按照车次hash ... 阅读全帖 |
|
e****2 发帖数: 2723 | 7 最近我写的数据库CODE
与民共享
Create view vw_order_cost as
Select o.orderid,o. orderdate, d.productid, c.companyname, (d.Quantity
* d.UnitPrice) as cost from orders o join orderdetails d on o.orderid=d.
orderid
Join customers c on o.customerid=c.customerid |
|
|
v***s 发帖数: 1893 | 9 举个例子
table1 userid infomation
userID (PK)
...
table2 order information
orderID (PK)
userID (FK)
....
table3 order detail
OrderDetailID (PK)
orderID (FK)
goodsID (FK)
....
一个人可以有N个orders, 一个order可以有N个商品。
这样三层搞下来table3就是个有很多很多的行大表格。如果是amazon这样的网站,几亿
行都在一个大表格内,query怎么办?
是从数据库设计方面去优化,还是从数据库软件和硬件方面去考虑? |
|
c*****d 发帖数: 6045 | 10 In Oracle, it should be,
select orderid,customername,
rank() over(partition by orderid order by customername)
from "order" ; |
|
a*******t 发帖数: 891 | 11 OK, here is a full working example:
CREATE TABLE [dbo].[testing](
[OrderID] [varchar](50) NULL,
[CustName] [varchar](50) NULL
)
and then insert some sample data into the table
123, John
567, Joe
123, Mary
123, Peter
and then here is the query
select
OrderID
, max(case rowno when 0 then CustName end) +
coalesce(max(case rowno when 1 then ', ' + CustName end), '') +
coalesce(max(case rowno when 2 then ', ' + CustName end), '') +
coalesce(max(case rowno when 3 then ', ' + |
|
c*****d 发帖数: 6045 | 12 你还是没看明白我上面说的
不管用户执行insert INTO ORDERITEMS (orderid,partid,qty)
还是insert INTO ORDERITEMS (orderid,detail,partid,qty)
或者说不管用户有没有提供detail
trigger都要忽略detail,然后改用max+1
不用trigger返回任何value |
|
P********R 发帖数: 1691 | 13 得到一出错信息如下
Msg 8144, Level 16, State 2, Procedure AddLineItem, Line 0
Procedure or function AddLineItem has too many arguments specified.
/* EXECUTE代码如下:*/
EXECUTE AddlineItem @vOrderid, @vPartid, @vQty, @vStr OUTPUT;
IF @vStr = 'Insert failed'
BEGIN
PRINT 'Insert failed'
PRINT 'FAILURE';
RETURN;
END;
ELSE
PRINT 'Insert successed!'
-- ENDIF;
PRINT 'SUCCESS.';
END;
/* the AddLineItem代码如下: */
IF EXISTS (SELECT name FROM SYS... 阅读全帖 |
|
m******u 发帖数: 12400 | 14 谢谢楼上两位,你们的理解是对的,一个orderid(一个order)可以有多个productid
(多个product)
只有orderid和production 1对1 对应的才是single-item order。 |
|
c*****d 发帖数: 6045 | 15 a.orderID肯定不能出现在group by里,如果orderID是不重复的 |
|
w****w 发帖数: 521 | 16 select CustomerID
from (
select a.CustomerID,a.OrderDate,a.SalesOrderID,COUNT(b.OrderDate) Cnt
from [Sales].[SalesOrderHeader] a join [Sales].[SalesOrderHeader] b
on a.CustomerID=b.CustomerID
where DATEDIFF(day,a.OrderDate,b.OrderDate) between 0 and 10
group by a.CustomerID,a.OrderDate,a.SalesOrderID
) c
group by c.CustomerID
having MAX(Cnt)>=5;
The key is for each order, count the number of orders in next 10 days.
OrderID here is for order identification, otherwise o... 阅读全帖 |
|
c*****d 发帖数: 6045 | 17 a.orderID肯定不能出现在group by里,如果orderID是不重复的 |
|
w****w 发帖数: 521 | 18 select CustomerID
from (
select a.CustomerID,a.OrderDate,a.SalesOrderID,COUNT(b.OrderDate) Cnt
from [Sales].[SalesOrderHeader] a join [Sales].[SalesOrderHeader] b
on a.CustomerID=b.CustomerID
where DATEDIFF(day,a.OrderDate,b.OrderDate) between 0 and 10
group by a.CustomerID,a.OrderDate,a.SalesOrderID
) c
group by c.CustomerID
having MAX(Cnt)>=5;
The key is for each order, count the number of orders in next 10 days.
OrderID here is for order identification, otherwise o... 阅读全帖 |
|
f**********w 发帖数: 93 | 19 I was askes a similar question, I gave the following data structure,
enum OrderType { BUY, SELL};
struct OrderInfo
{
// order information
double price;
OrderType ot;
int shares;
};
struct PriceComparator{
// compare OrderInfo based on price
bool operator() (const OrderInfo& lhs, const OrderInfo& rhs)
{
return lhs.price > rhs.price;
}
};
use hash_map to look up stockname from
orderId;
then use
hash_map |
|
|
i****k 发帖数: 4085 | 21 用户信息的安全性似乎真出了问题,昨日“泄露门”又有了升级版。在“天涯被黑”
、“当当(微博)网用户资料泄密”事件之后,昨日,挨踢客网站上再爆猛料,有网友提
供消息称,多家银行用户资料外泄。随后,涉及到的银行均对此事予以否认。
涉及银行齐否认
“这纯属谣言”。该消息中所涉及到的银行随后均发布澄清公告,并异口同声地表
示,经核查,网站上贴出来的用户信息均属伪造。
挨踢客提供的消息显示,国内多家银行的用户数据已经泄露,其中交通银行(4.48,
0.02,0.45%)7000万、民生银行(5.89,0.07,1.20%)3500万。该网站称无法核实数据的真
实性,但贴出的截图显示,泄露数据的银行包括交通银行、民生银行、工商银行(4.24,
0.04,0.95%)等,数据包含了用户的姓名、卡号、密码等敏感信息。
工行相关负责人表示,网上贴出的所谓泄漏用户数据中所涉及的三张该行银行卡均
为已注销的无效卡,且其中包含了订单号(OrderId)等内容,可以判断信息不是来自银行
数据库。
此外,交通银行发布声明表示,将保留追究散步谣言者法律责任的权利。
“安全U盾”已不安全?
虽然各家涉及到的银行均对此... 阅读全帖 |
|
|
|
|
|
|
p***n 发帖数: 635 | 27 两个表:
Customer
CustomerID,Name
Order
OrderID,CustomerID做FK
1 2
2 5
3 8
4 2
5 2
6 8
写个查询语句,返回数据对:
订单数 客户数目
譬如上边的表总结一下就是这样:
1 1
2 1
3 1 |
|
N*D 发帖数: 3641 | 28 来自主题: JobHunting版 - 发个面试题 class Customer {
String id;
State state; // assume it asks for customers who live in certain state,
not state of shipping address of an order.
Gender gender;
List orders;
}
class Order {
String orderId;
Customer customer;
List> itemQuantityPairs;
}
class Item {
String itemId;
Double unitPrice; // in $
} |
|
S*******o 发帖数: 2 | 29
昨晚在网上买的电话卡,试了很多次,very annoying。不过以下是我的经验
1。 使用英文界面
2。 clean up the history of your browser by clicking tools/internet options/
3. make sure your IE is using 128 bit encryption by clicking help/about
4. 当你make payment时,记下orderid, 如果看不到密码,可以打电话:8610-88511155
x6826, or 6811, 6817 etc,查询是否你的order 成功,或者查询技术问题。打电话021-
50544510 x8638 or 8648查询密码。
5。可以在晚一些时候上网,这样server也许会有反应。 |
|
s*****l 发帖数: 2776 | 30 把你的orderid发给kf,说明你需要更新你的保修,大概两天,就会给你改过来 |
|
|
|
c*******y 发帖数: 1630 | 33 OK, I figure it out.
solutions:
1. use orderID of the first order of the group which is unique anyway.
2. use system time |
|
w***o 发帖数: 3830 | 34 来自主题: PHILADELPHIA版 - bingo 杂志名称 订阅说明 数量
女友 从2002年9月开始,到2002年12月,共4月 1
青年文摘 从2002年9月开始,到2002年12月,共4月 1
TotalPrice: US$22.40
OrderID: MGZ189845
您可以登陆您的个人帐户查询您的订阅记录 |
|
p**o 发帖数: 3409 | 35 Hello,
We now have delivery date(s) for the order you placed
on March 28, 2012 (Order# **********):
"StarCraft II: Heart of the Swarm"
Estimated arrival date: March 12, 2013
If you want to check on the progress of your order,
take a look at this page in Your Account:
https://www.amazon.com/gp/css/summary/edit.html?orderID=**********
We hope to see you again soon!
Sincerely,
Customer Service Department
http://www.amazon.com |
|
|
|
|
C****c 发帖数: 9157 | 39 不是我的,我还没收到..这人是Feb 06的蛋
一下子推到5月了....
amazon发出去的最晚的单现在应该在Feb 06 10:30pm~11:00pm之间
--------
Hello,
We now have delivery date(s) for the order you placed on February 06, 2012 (
Order# 105-8506XXX-435XXXX):
"Nikon D800 36.3 MP CMOS FX-Format Digital SLR Camera (Body Only)"
Estimated arrival date: May 02, 2012 - May 03, 2012
If you want to check on the progress of your order, take a look at this page
in Your Account:
https://www.amazon.com/...gp/css/summary/edit.html?orderID=105-850XXX-
435XXXX
We ho... 阅读全帖 |
|
C****c 发帖数: 9157 | 40 Hello,
We now have delivery date(s) for the order you placed on February 07, 2012 (
Order# 105-3963XXX-4809XXX):
"Nikon D800 36.3 MP CMOS FX-Format Digital SLR Camera (Body Only)"
Estimated arrival date: May 08, 2012
If you want to check on the progress of your order, take a look at this page
in Your Account:
https://www.amazon.com/gp/css/summary/edit.html?orderID=105-3963XXX-4809XXX
We hope to see you again soon!
Sincerely,
Customer Service Department
http://www.amazon.com |
|
|
|
D*******r 发帖数: 37 | 43 【 以下文字转载自 Database 讨论区,原文如下 】
发信人: DVDplayer (专放DVD VCD), 信区: Database
标 题: 问关于group by的问题
发信站: Unknown Space - 未名空间 (Sat Mar 5 01:16:54 2005) WWW-POST
My table has following fields:
OrderID, Customer, Price, Quantity
Then how I can get the total price by Customer for all Customers?
Thanks in advance. |
|
D*******r 发帖数: 37 | 44 My table has following fields:
OrderID, Customer, Price, Quantity
Then how I can get the total price by Customer for all Customers?
Thanks in advance. |
|
m**********2 发帖数: 2252 | 45 有2个table
table1:
tablID, CustomerID, inquery code,inquerydate
34, 12345, A, 1/1/2010
35, 12346, A, 1/3/2010
36, 12345, B, 1/5/2010
37, 12346, B, 1/8/2010
38, 12345, C, 1/20/2010
39, 12346, C, 1/24/2010
......
table2:
orderID, CustomerID, orderdate
2001, 12345, 1/15/2010
2002, 12346, 1/12/2010
我现在想做个report,如下结果:
customerID, inquery code,inquerydate
12345, B
12346, B
就是说,找出的inquery code在orderdate之前的最后一次。
包子谢! |
|
c*****d 发帖数: 6045 | 46 作为新手,你可以把这个简化成几个步骤
1. 写一个trigger,这个trigger能够在用户执行insert INTO ORDERITEMS (orderid,
partid, qty)的时候自动产生一个新的detail,现在可以先用max+1,以后学了
sequence可以修改
2. 上面这个trigger实现了,并测试之后写存储过程,存储过程其实就是简化了insert
语句,只要提供i_Orderid, i_partid, i_Qty |
|
P********R 发帖数: 1691 | 47 谢谢!
就是这样做的,但好象trigger自动产生的新的detail不能在INSERT的时候读取。
在trigger里用了:
SELECT NVL(MAX(detail), 0) + 1
INTO v_Newdetail
FROM ORDERITEMS
WHERE orderid = v_Orderid;
:new.detail = v_Newdetail;
,
insert |
|
P********R 发帖数: 1691 | 48 IF EXISTS (SELECT name FROM SYSOBJECTS WHERE name = 'GetNewDetail')
BEGIN DROP PROCEDURE GetNewDetail; END;
GO
CREATE PROCEDURE GetNewDetail
@vOrderid SMALLINT,
@vNewDetail SMALLINT OUTPUT
AS
BEGIN
SELECT @vNewDetail = MAX(ISNULL((detail), 0)) + 1
FROM ORDERITEMS
WHERE orderid = @vOrderid;
END; |
|
z0 发帖数: 71 | 49 select a.CustomerID ,
a.OrderDate ,
a.OrderID
from your_table a
join your_table b
on a.CustomerID = b.CustomerID
and a.OrderDate between b.OrderDate - 10 and b.OrderDate
group by 1,2,3
having count(1) >= 10 ; |
|