由买买提看人间百态

topics

全部话题 - 话题: queries
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
i******7
发帖数: 421
1
哦.我可能没有说清楚.实际上这个calltime的格式是:mm/dd/yyyy hh:mm:ss的.所以觉
得那个+1可能不work.如果格式包括时间,该怎么写呢?

发信人: cheungche (你不乖), 信区: Database
标 题: Re: 请教一下这个report的query应该怎么样写?
发信站: BBS 未名空间站 (Mon Oct 18 18:44:55 2010, 美东)
先做一个辅助table
select phonenum ,
min(calltime) as min_calltime
from your_table
group by 1
然后数的时候用case
select a.phonenum ,
count(case when a.calltime between b.min_calltime and b.min_calltime
+ 1
then a.phonenum else null end) as day1_cnt ,
...
from your_tabl... 阅读全帖
f*******l
发帖数: 87
2
困惑:
运行同样的select query在同一数据库, 我获得的数据比其他人的少。
是不是设置的问题? 请教帮助,万分感谢!
a***y
发帖数: 2803
3
我自己的notepad里面query结果和公司计算机的结果也不同.我自己的计算机里面会自
动出现中文,公司的是英文的.所以可能和计算机里的操作系统有关.
而且,' 和",在有中文的系统里会被sql认为不合语法,要改成英文版的引号和双引号.
i****i
发帖数: 43
4
别人发过来一个Access 文件,他用的是Access2003, 我用的是Access 2007. 在打开里
面的queries时,出现:not a valid path error. 当我按右键design view 打开时,出
现的是SQL.我是Access新手,请各位高手指点.谢谢.
i****i
发帖数: 43
5
如果双击这个query,出现的是
'........' is not a valid path. Make sure that the path name is spelled
correctly and that you are connected to the server on which the file resides
.
i****a
发帖数: 36252
6
query looks fine from a brief look
can you browse the linked tables? check linked table setting to make sure
they are valid

resides
i****a
发帖数: 36252
7
it's better to fix the original linked table, cause other queries may
still be using that.
right click on the linked table, and say "linked table manager"

d*********s
发帖数: 777
8
来自主题: Database版 - 请教oracle sql query question
有两列数据column A, column B相同类型
如果column A不为空,就select column A, 如果column A为空就select column B
query怎么写啊?
谢谢
y****9
发帖数: 144
9
来自主题: Database版 - 什么query builder好用啊
If you are dealing with Oracle, you may try Oracle SQL Developer 3.0 .
Myself do not have experience on query builder. Just know came to know this
feaute in the recent OTN developer day
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/sq
i*****w
发帖数: 75
10
Not sure if this is what you wanted, check the following query.
If you want to include future category names, then you need to use dynamic
SQL to get the distinct values in the category name column and then it will
pivot for you when you have new category name. For example, if you have a
new record with Category 4 and then Category 4 will be added to the result
grid.
declare @myTable table(id integer,category char(10),value float)
insert into @myTable values(1, 'category 1', 128)
insert into @my... 阅读全帖
i****a
发帖数: 36252
11
来自主题: Database版 - SQL Server Update Query - non-unique value
If the where clause in an update query hit multiple records for the same row
, which one gets written as the final update?
example
TableA:
Name, Value
A, 100
A, 200
A, 300
update TableB
set col1 = TableB.Value
from TableB
where TableB.Name = 'A'
i think it is by physical order but not guaranteed?
g***l
发帖数: 18555
12
select 1 from T2 where T1.ID1 = T2.ID2 是MULTI RECORDS?
我不知道你这个QUERY到底想实现什么, SET里面的JOIN跟WHERE EXISTS里的没啥关系
,本来应该是很简答的JOIN吧
Update
T1
set
value1 =t2.value2
from
table T1
inner join
table T2 on
(
T1.ID1= T2.ID2
)
i****i
发帖数: 18
13
来自主题: Database版 - How to write the query
I tried to use SQL server to get the aggregated donation summary (close date
between 10/1/2010 and 10/2/2011), and then put them into a new column.
I don't know how to write the query.
These data are downloaded from Salesforce platform, and I don't know whether
I can use SQL server to get the answer.
Here is the sample data:
Record ID Full Name Close Date Amount Sum
CON-737993 B Wanitta 12/21/2011 75
CON-737993 B Wanitta 11/21/2011 25
CON-194654 A. Bertsch ... 阅读全帖
g***l
发帖数: 18555
14
来自主题: Database版 - How to write the query
要先SELECT DISTINCT Record ID, Full Name,然后LEFT OUTER JOIN那个 GROUP BY 的
QUERY,没有的为NULL
i****a
发帖数: 36252
15
来自主题: Database版 - SQL Query Question
example has been super simplified. the sub query only returns 1 value, or no
value.
it's basically to check if a record exists, if yes, return value, if not,
use a default value.
but I've taken it out of subquery and made it its own logic block for
another reason.
s******0
发帖数: 13782
16
来自主题: Database版 - QUERY TOOL 求推荐
data source comes from multiple platforms, such as SQLSERVER, DB2 or even a
plain text file, while target is an Oracle data warehouse.
anyone can recommend a nice query tool, which easily connect to any source
and make my data comparison job faster, easier?
B*********L
发帖数: 700
17
来自主题: Database版 - 这个query怎么写?
DECLARE @MARKET varchar
SET @MARKET = 'NY,NJ,CH'
SELECT COUNT(*)
FROM TABLE_X
WHERE MARKET_ID IN ( @MARKET )
希望 IN ( 'NY','NJ',CH' ), 而不是 in ('NY,NJ,CH'), 但是不知道怎么去set 这个
@Market。
Set @Market, 是因为后面跟着几十个query,每个都要where 这个@market
谢谢。
J*****u
发帖数: 44
18
来自主题: Database版 - 向大牛请教 query问题啊!
有三张表
表名一 csm
table1
a-1,toi01
a-2,toi01
a-3,toi01
a-4,toi02
a-5,toi02
表名二 oem
table2
m-1,toi01
m-2,toi01
m-3,toi02
m-4,toi02
表名三 prt
table3
toi01,lam,45
toi02,eod,18
想得到下面这样的结果
a-1/lam/45/m-1/m-2 (需要一个query,而且结果是同一行),刚刚入门数据库,谢谢
大牛解答
J*****u
发帖数: 44
19
来自主题: Database版 - 向大牛请教 query问题啊!
有三张表
表名一 csm
table1
a-1,toi01
a-2,toi01
a-3,toi01
a-4,toi02
a-5,toi02
表名二 oem
table2
m-1,toi01
m-2,toi01
m-3,toi02
m-4,toi02
表名三 prt
table3
toi01,lam,45
toi02,eod,18
想得到下面这样的结果
a-1/lam/45/m-1/m-2 (需要一个query,而且结果是同一行),刚刚入门数据库,谢谢
大牛解答
k********e
发帖数: 702
20
来自主题: Database版 - sqlserver Query的问题
update statistics是必须的。当然,其实更应该先defrag/reindex一下(尤其是
cluster index),信不信由你。
另外,高版本的SQL可以绑定execution plan,当然,你index hint也可以。没什么不
好的。query optimizer本来就不能保证100%最优。
对了,我是web developer。我都知道这个。
e****7
发帖数: 4387
21
来自主题: Database版 - sqlserver Query的问题

不能吧,占用太多资源,同时还增加query optimizer 的工作量。
i****a
发帖数: 36252
22
来自主题: Database版 - sqlserver Query的问题
is this query in a stored procedure?
e****7
发帖数: 4387
23
来自主题: Database版 - sqlserver Query的问题

LZ didn't mention, assumed not, otherwise re-compile the proc will force the
query optimizer to re-create exe plan.
p********l
发帖数: 279
24
来自主题: Database版 - sqlserver Query的问题
看一下你的Query里面有没有Implicit Cast,很多时候就是因为这个而没有选择最优的
index
r**********e
发帖数: 194
25
来自主题: Database版 - 弱问一个sql的query问题
小弟想了半天也没啥思路,想上来请教诸位大牛
现在有四个table
PEAK (NAME, ELEV, DIFF, MAP, REGION)
CLIMBER (NAME, SEX)
PARTICIPATED (TRIP_ID, NAME)
CLIMBED (TRIP_ID, PEAK, WHEN_CLIMBED)
Your assignment is to write SQL queries that answer the following question
A repeat ascent of a peak is defined as any ascent after the first one by a
particular person. So if a person climbs a peak three times, and another
person climbs that peak four times, the peak has five repeated ascents. Find
the ten peaks with the greatest number of ... 阅读全帖
y*******u
发帖数: 930
26
来自主题: Database版 - 弱问一个sql的query问题
首先match join(2个TRIP_ID相等) PARTICIPATED和climbed, 形成par-climbed,
这里面就是哪个人 去了啥peak
然后对新的这个relation group over (NAME,PEAK) 就得出啥人登啥山几次,然后
projection 算出来一个新column 把登几次都减一,
最后group over PEAK, 算出你要的东西。

小弟想了半天也没啥思路,想上来请教诸位大牛
现在有四个table
PEAK (NAME, ELEV, DIFF, MAP, REGION)
CLIMBER (NAME, SEX)
PARTICIPATED (TRIP_ID, NAME)
CLIMBED (TRIP_ID, PEAK, WHEN_CLIMBED)
Your assignment is to write SQL queries that answer the following question
A repeat ascent of a peak is defined as any ascent after the first one by... 阅读全帖
n******1
发帖数: 3756
27
你怎么确保是同样一个query?
d*********t
发帖数: 277
28
初学SQL,XML和JSON Data,querying XML要不要学,如果要,是放在SQL之前还是之后
,谢谢大家。
B*****g
发帖数: 34098
29
你不会sql怎么query?
u*l
发帖数: 1943
30
来自主题: Database版 - MySql如何Web Query?
架了个MySql Server, 需要给不懂SQL的人使用,功能就是简单的基于Web界面的Query
(比如Select),请问大虾们怎么解决?
B*****g
发帖数: 34098
c******n
发帖数: 7263
32
来自主题: Database版 - MySql如何Web Query?
这个server是自己搞得还是公司搞的?硬件几何?

Query
y*****g
发帖数: 677
33
来自主题: Database版 - MySql如何Web Query?
I have never heard there is such a free tool to do web query to mysql db.
s***s
发帖数: 1301
34
我有两个个表Table A 有3个column Col1, Col2, Col3,和Keyword Table B it has
keyword1, keyword2, keyword3.....
我想查Table A 中有哪些record, 其任何一个column (Col1, or Col2, or Col3) 有
任何一个Table B 中keyword 。
我想到的方法是:
利用cursor 来获取一个一个keyword, 然后传到@p1 下面的dynamic query来查取
select *
from A
where Col1 like '%@p1%' or Col2 like '%@p1%' or Col3 like '%@p1%'
问题是我的keyword table可能有上千个,这种方法就比较低效。
请问有什么比较好的方法来实现呢?
谢谢!
k*z
发帖数: 4704
35
DB2出来的时间大多数是Hundred Year Date, 我现在写了一个query可以把时间取出来
,但是格式是datetime, 我怎么才能转成date?
ELECT date(days('1899-12-31')+HYD) as SQLDate,
Year(date(days('1899-12-31')+HYD)) as Year,
Month(date(days('1899-12-31')+HYD)) as Month,
Day(date(days('1899-12-31')+HYD)) as Day,
FROM DB2.Table
谢谢。
m**c
发帖数: 192
36
来自主题: Database版 - 请教高手关于database query的问题
假设requirement里面没有很强的data integrity的要求。
两个table里面的字段完全一样。里面的数据也一样,都是百万级别的。一个table里面
定义了foreign key,另外一个table里面没有定义foreign key。同一个SQL query哪一
个速度比较快?
C***y
发帖数: 2546
37
来自主题: Database版 - 请教一个query
有两张表
表一:
id, date, spend
表二:
id, date
我想得到表二每一行的id,对应date的前30天的sum(spend),和后30天的sum(spend)
我能想到的就是写个程序iterate表二里的每一行,然后每一行query表一一次
请问一下这个能用纯sql语言,比如说join实现吗?
非常感谢!
l******9
发帖数: 579
38
【 以下文字转载自 Quant 讨论区 】
发信人: light009 (light009), 信区: Quant
标 题: error run SQL query from pyodbc python 3.2.5
发信站: BBS 未名空间站 (Thu Jun 19 12:04:26 2014, 美东)
I am working on pyodbc in Eclipse (4.3.2v20140221-1852) with PyDev on Win 7.
My python is 3.2.5.
At my code:
cursor.execute("select top " + str(1) + " a.my_id, a.mycode" +
"from my_table as a where a.mycode = ?", aGivenCode)
I got an error :
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server
Driver]
[SQL Ser... 阅读全帖
A*******n
发帖数: 625
39
来自主题: Database版 - 为何query这么慢?
谢谢, 要是用程序还简单一点,老板只要query现在,我用sql server,‘FOR XML
PATH’可以解决我的问题。 和你说的mysql可以在join后用group_concat差不多一个意
思。 谢谢
A*******n
发帖数: 625
40
来自主题: Database版 - 为何query这么慢?
谢谢。
非常同意你的3和4,主要是老板要在business的基础上找出所有的错误,有数据错,有
顺序错,有数据丢失错。
这其实很费劲。所以有的时候有的问题没考虑到,等你知道的时候,你的table就可能
不止scan一次了。而且我还不能改数据库,比如说加index,PK。而且今天告诉你
business是这样,过一个月说有变动。所以很难从头规划query,只能在现有的基础上
想办法改,速度不要太慢就好了。30seconds 我觉的ok了。有的时候不常用某个语法,
就会用老办法,所以有的时候就很慢。 酷毙大师说的"FOR XML PATH"帮我解决了loop
的问题,这语法用过,只是不常用,有的时候想不起来。 呵呵
d******a
发帖数: 32122
41
虽然都能处理
有没有比SQL Server还优化的?前提是建立query要有图形界面, 直接写SQL太累
t***u
发帖数: 368
42
blow query is VERY slow: > 15 mins, any suggestions appreciated !!
@tempTable ~ 20k data
#ExpTable ~ 500k data
declare @tempTable table
(

data_id int,

Q float,

Qtype int
)
create table #ExpTable
(
data_id int,

B1 float,
B2 float,
B3 float,
B4 float,
B5 float,

B6 float,
B7 float,
B8 float,
B9 float,
B10 float
)



... 阅读全帖
l******b
发帖数: 39
43
connect the DB as HR user, issue the following query
select table_names from user_tables ;
m******u
发帖数: 12400
44
来自主题: Database版 - 这个query怎么写?谢谢
the query is not right. too many rows selected.
d**********3
发帖数: 1186
45
3月份开课的Query MS SQL Server. BI 的第一步。
http://www.passtraining.net/
g*********g
发帖数: 171
46
来自主题: Database版 - 这2个query哪个快点,为啥
My guess is that the comparison is for the following two queries
select count(ID) From (select ID from A UNION ALL select ID from B);
select sum(cid) from (select count(ID) cid from A UNION ALL select count(ID)
cid From B);
My intuition is that the second one might be a bit faster.
b*****n
发帖数: 2324
47
来自主题: Database版 - 问一个query
请问这个query执行起来会efficient嘛?
http://www.codeproject.com/Articles/300785/Calculating-simple-r
SELECT a.id, a.value, (SELECT SUM(b.value)
FROM RunTotalTestData b
WHERE b.id <= a.id)
FROM RunTotalTestData a
ORDER BY a.id;
只扫描table一遍吗?谢谢
m******u
发帖数: 12400
48
来自主题: Database版 - 这个query对么?
你说的对,date作为column head要加中括号。你的query更好一些。我的实在是太难看
了。
m*********a
发帖数: 3299
49
来自主题: Database版 - 这个query对么?
我的SQL没有正式学过,就是工作中有很多的server side 的SQL
所以我不是dba,就是一个用到简单SQL 的吗农
我没有看懂你说的date要加括号是啥意思
这个query在你的系统,我猜是microsoft sql server中可以run不?
m******u
发帖数: 12400
50
来自主题: Database版 - 这个query对么?
已经做了相应改动:将date加中括号,还把最后一行换成了id相减(date类型不能相减
),但仍不能run。我的那个query能run,并能给出正确结果。
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)