Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query without max()
Message
From
15/09/2019 03:55:05
 
 
To
14/09/2019 01:21:51
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01670845
Message ID:
01670864
Views:
82
Likes (1)
>Sir,
>
>While using SQLSERVER 2012, I have these codes
>
>
>USE at18;
>IF OBJECT_ID('tempdb.dbo.#Table1', 'U') IS NOT NULL
>  DROP TABLE #Table1; 
> 
>CREATE TABLE #Table1
>(
>code VARCHAR(50),
>	names VARCHAR(50),
>	country VARCHAR(50),
>	qty int
>)
>
>INSERT INTO #table1 VALUES (1104,'ERIC','Holland',45)
>INSERT INTO #table1 VALUES (1105,'Boris','Bulgaria',50)
>INSERT INTO #table1 VALUES (1106,'Anil','India',75)
>INSERT INTO #table1 VALUES (1107,'Cetin','Turkey',65)
>INSERT INTO #table1 VALUES (1105,'Boris','Bulgaria',40)
>INSERT INTO #table1 VALUES (1104,'ERIC','Holland',65)
>INSERT INTO #table1 VALUES (1107,'Cetin','Turkey',85)
>INSERT INTO #table1 VALUES (1106,'Anil','India',25)
>
>select * from #table1 order by code
>
>select code,max(names)as names,max(country)as country,sum(qty)as qty 
>from #Table1
>group by code
>order by code
>
>
>The codes work fine like shown in attachment.
>
>I used max() clause to get all other columns except column that I used in group by.
>
>Is there any other methods to get above result without using max() clause?
>
>I mean ;With CTE or Join
>
>Please help
select DISTINCT code, names, country	
        ,	SUM(qty) OVER (PARTITION BY code)
       from #Table1 order by code
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform