由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - ask for help with a simple query!!!
相关主题
问个SQL问题SQL select one value column for each distinct value another (转载)
a sql questionSQL求助
SQL run a stored procedure by fetching from a cursor row by row服了,这就是我们QA和DBA的水平
请教SQL server的一个programming的问题,谢谢老印给我的一个Challenge
help about SQL for ACCESS[转载] Can anyone interpret this simple SQL?
SQL server 2000有hidden records吗?SQL combine two columns from two different tables no shared (转载)
SQL中怎样用定制列排序?how to get the product for a column
SQL find distinct values in large tableMS SQL database engineer(sr)ONSITE 面试该如何准备?
相关话题的讨论汇总
话题: productid话题: query话题: use话题: simple
进入Database版参与讨论
1 (共1页)
p*p
发帖数: 80
1
Could someone help me with the following query? Say there is a table with 2
columns, ProductID and ProductType
ProductID ProductType
1 C
2 B
3 A
4 B
5 A
6 C
7 A
8 B
how to write a query to return 2 products (order by ProductID) from each
producttype? In this case, return:
3 A
5 A
2 B
4 B
1 C
6 C
Use Transact-SQL, one query, no cursor is allowed.
Please help!!!!
c**t
发帖数: 2744
2
select * from table
where productID in (select distinct productID from table
having count(ProductType) = 2
)
order by productType

【在 p*p 的大作中提到】
: Could someone help me with the following query? Say there is a table with 2
: columns, ProductID and ProductType
: ProductID ProductType
: 1 C
: 2 B
: 3 A
: 4 B
: 5 A
: 6 C
: 7 A

j**i
发帖数: 419
3
Looks like this is not what he means, he wants
everything be returned twice, even count(*) may >2,
right?
in oracle you can use rownum to do this bah.

2

【在 c**t 的大作中提到】
: select * from table
: where productID in (select distinct productID from table
: having count(ProductType) = 2
: )
: order by productType

k***e
发帖数: 12
4
select p.* from product p
where p.productid in (select top 2 productid from product where
producttype=p.producttype)
order by producttype,productid

with

【在 j**i 的大作中提到】
: Looks like this is not what he means, he wants
: everything be returned twice, even count(*) may >2,
: right?
: in oracle you can use rownum to do this bah.
:
: 2

j**i
发帖数: 419
5

This is not good in oracle bah.
which do you use?miscrosoft sql server?
each

【在 k***e 的大作中提到】
: select p.* from product p
: where p.productid in (select top 2 productid from product where
: producttype=p.producttype)
: order by producttype,productid
:
: with

1 (共1页)
进入Database版参与讨论
相关主题
MS SQL database engineer(sr)ONSITE 面试该如何准备?help about SQL for ACCESS
请教SQLSQL server 2000有hidden records吗?
SQL Server - how to obtain data type nameSQL中怎样用定制列排序?
气死我了SQL find distinct values in large table
问个SQL问题SQL select one value column for each distinct value another (转载)
a sql questionSQL求助
SQL run a stored procedure by fetching from a cursor row by row服了,这就是我们QA和DBA的水平
请教SQL server的一个programming的问题,谢谢老印给我的一个Challenge
相关话题的讨论汇总
话题: productid话题: query话题: use话题: simple