SQLTeam.com | Weblogs | Forums

SQL query, not show report if previous value is same

Need help,

Here is returned data:

Screenshot_5

Please see picture.
I want see 'blank' row, if those tree row:s are same. I mean, all row:s still here but double row is without any value (blank).

Is this possible?
Can't use Lag() because solid server.

Thanks

need more info than this. DDL, sample data and expected output would help as well. Don't know what you mean by this:

I want see 'blank' row, if those tree row:s are same. I mean, all row:s still here but double row is without any value (blank).

1 Like

Here is what i mean.

SQL Query:

SELECT DISTINCT TYA_TYONRO, TYA_ALKUKLO, TYA_LOPPUKLO, MTR_RIVINRO, TYA_TEKIJA, MTR_TYOKOODI, MTR_TEHTAVA, MTR_ARVIOAIKA, IFNULL(TIMESTAMPDIFF(1,TYA_ALKUKLO,TYA_LOPPUKLO),0)/3600 ID9
FROM TYOAIKA 
INNER JOIN MAARTYO ON MTR_NRO = TYA_TYONRO
GROUP BY TYA_TYONRO, TYA_ALKUKLO, TYA_LOPPUKLO, MTR_RIVINRO, TYA_TEKIJA, MTR_TYOKOODI, MTR_TEHTAVA, MTR_ARVIOAIKA
ORDER BY TYA_ALKUKLO ASC

What you are asking for is normally done in the reporting/application layer - not in the data layer or database.

Since you haven't provide any useful sample data - all I can do is generalize an approach. One approach would be to add a row_number for each 'group', then check the row number value and 'blank' any columns where that row number is not equal to 1.

It is quite useless to use both DISTINCT and GROUP BY in the same query. Either one or the other and since you are not aggregating any data - no reason to use a GROUP BY. Further - using DISTINCT shouldn't be necessary if your join criteria and filters are correctly set.

Finally - since this site is for Microsoft SQL Server and you are definitely not using that product you may not get a solution that will work on your flavor of SQL.

2 Likes

so what @mike01 and @jeffw8713 are asking you can be provided as follows. Since we do not have access to your server/database, unless you provide sample data it would very hard to help you

so provide your data not as an image but as follows

declare @zimzam table(MTR_NRO int,  TYA_ALKUKLO string,  --etc

insert into @zimzam
values(49186, '1.6.2022 7:29:00', --etc

making sure to provide all of the data. That way we have your data and we can use it in our sql server and help us help you

1 Like

Thanks for messages.

Sorry i don't know how i can provide sample data here? (copy txt like .csv here?).

here it is repeated again.

declare @sampledata table(MTR_NRO int,  TYA_ALKUKLO string,  --etc

insert into @sampledata
values(49186, '1.6.2022 7:29:00', --etc

like the following post as an example

Your code doesn't look like it's for SQL Server.

Which dbms (MySQL, Postgre, etc.) are you using?