Skip to content

Tag: sql

All tables consisting of numbers less than a fixed number

I am trying to find out all the tables where table names consist of numbers less than a fixed number 16284961 at the end preceded by an underscore for example LOG_16282961. Sample User_segments table: Expected Output: Query: Using above query, although I am getting my result but additionally it also includes …

Pivot data T-SQL

I have the following table: I want to pivot it to the following table: I tried to work with the following example: https://www.sqlshack.com/dynamic-pivot-tables-in-sql-server/ But in this case a SUM operator is mandatory. I don’t want to use the SUM operator for my data. What would be the best approach …

sort with special sort number

I have two tables, sort table and assign table SortID Name 0 A 1 B 2 C 3 D I want assign mission to everyone, start with a special sortID example: start with sortID 2, and change order next week. result as below: Date Week MissionA MissionB MissionC MissionD 2021/1/3 1 C D A B 2021/1/4 1 C D A

Find rows where sum of columns from multiple rows is greater than X

The best way to explain this question is through the real life example it would solve. I have two tables, Match Overview and Match Attributes Match overview looks like While match attributes looks like Where match_id is a foreign key for id in the match overview table, and attribute id is the integer represen…

Casting Decimal to Currency in AWS Athena

I have a field value(decimal(23, 2)) and I am querying over it like this: sum(value) and as output i get 1200000.32 I am trying to cast it to currency to get $1.200.000,32 like this: How can I get the desired currency type? Answer There is no money type in presto. And Amazon’s version of presto does not…