sql

mysql distinct values without empty string and NULL

别来无恙 提交于 2021-02-18 18:15:11
问题 How to retrieve mysql distinct values without empty string value and NULL value SELECT DISTINCT CON.EMAILADDRESS AS 'E-MAIL' FROM STUDENT INNER JOIN CONTACT CON ON STUDENT.CONTACT_ID = CON.ID WHERE (CON.EMAILADDRESS IS NOT NULL OR CON.EMAILADDRESS !=' '); But in output still getting empty e-mails too. Can't figure out what wrong I am doing. 回答1: Try this: SELECT DISTINCT CON.EMAILADDRESS AS 'E-MAIL' FROM STUDENT AST INNER JOIN CONTACT CON ON AST.CONTACT_ID = CON.ID WHERE length(trim(CON

Replace all non numeric characters in MSSQL with an empty string

拈花ヽ惹草 提交于 2021-02-18 18:04:16
问题 My current MSSQL table has a "phone" column which is a varchar. Unfortunately, the phone numbers that are already in the database are not in standard format. For example, 888-888-8888 OR 888/888/8888 OR (888)8888888 OR 8888888888. I want to get all the rows that are equivalent to 88888888, i.e it should match with 888-888-8888, (888)888888 etc. I have tried using REPLACE() but there are certain rows where entries have other alphabetic characters like "e", "ex", "ext", etc. So I would like to

How to make repeating custom expressions in SQL queries maintainable

天大地大妈咪最大 提交于 2021-02-18 17:50:06
问题 Imagine the following simple query, where I get a list of all users that were created within the last 3 days, the logic or example is not important SELECT ... , DATEDIFF(DAY, U.DateCreated, GETUTCDATE()) ... FROM dbo.AspNetUsers U WHERE DATEDIFF(DAY, U.DateCreated, GETUTCDATE()) < 3 I've repeated some code DATEDIFF(DAY, U.DateCreated, GETUTCDATE()) < 3 which, when I have much more complicated examples of the above I don't want to maintain twice or however many times I need that logic. How

sqlite - find recipes that can be made from a set of ingredients

若如初见. 提交于 2021-02-18 17:09:53
问题 Right now I am using sqlite within a ios application, and I want to be able to search for recipes that can be made from a list of ingredients (ie recipes such that are a subset of the provided ingredients) For example: Recipe 1: A B C Recipe 2: A B Recipe 3: C D Recipe 4: A Recipe 5: E Query for ingredients A B C returns recipes {1, 2, 4} Query for ingredients A B returns recipes {2, 4} Query for ingredients D returns {} Currently what I have set up is Table Items name text primary key Table

sqlite - find recipes that can be made from a set of ingredients

为君一笑 提交于 2021-02-18 17:07:33
问题 Right now I am using sqlite within a ios application, and I want to be able to search for recipes that can be made from a list of ingredients (ie recipes such that are a subset of the provided ingredients) For example: Recipe 1: A B C Recipe 2: A B Recipe 3: C D Recipe 4: A Recipe 5: E Query for ingredients A B C returns recipes {1, 2, 4} Query for ingredients A B returns recipes {2, 4} Query for ingredients D returns {} Currently what I have set up is Table Items name text primary key Table

Spark Dataframe: Select distinct rows

狂风中的少年 提交于 2021-02-18 17:00:20
问题 I tried two ways to find distinct rows from parquet but it doesn't seem to work. Attemp 1: Dataset<Row> df = sqlContext.read().parquet("location.parquet").distinct(); But throws Cannot have map type columns in DataFrame which calls set operations (intersect, except, etc.), but the type of column canvasHashes is map<string,string>;; Attemp 2: Tried running sql queries: Dataset<Row> df = sqlContext.read().parquet("location.parquet"); rawLandingDS.createOrReplaceTempView("df"); Dataset<Row>

Spark Dataframe: Select distinct rows

拜拜、爱过 提交于 2021-02-18 17:00:14
问题 I tried two ways to find distinct rows from parquet but it doesn't seem to work. Attemp 1: Dataset<Row> df = sqlContext.read().parquet("location.parquet").distinct(); But throws Cannot have map type columns in DataFrame which calls set operations (intersect, except, etc.), but the type of column canvasHashes is map<string,string>;; Attemp 2: Tried running sql queries: Dataset<Row> df = sqlContext.read().parquet("location.parquet"); rawLandingDS.createOrReplaceTempView("df"); Dataset<Row>

SQL Server 2012: Select Top n based on multiple criteria

时间秒杀一切 提交于 2021-02-18 16:59:32
问题 Pretty new to SQL here - help would be much appreciated. I have a table with Region , Month , Member ID , and Sales (with multiple transactions per member). I just want to extract the top 2 members, based on sum of sales, per region, per month....so essentially: Region Month MemberID Sales ----------------------------------------- 1 1/1/2013 A $200 2 2/1/2013 B $300 1 1/1/2013 A $100 1 1/1/2013 B $50 2 1/1/2013 D $500 2 2/1/2013 C $200 Becomes: Region Month Member ID Sales -------------------

SQL Server 2012: Select Top n based on multiple criteria

谁说胖子不能爱 提交于 2021-02-18 16:59:09
问题 Pretty new to SQL here - help would be much appreciated. I have a table with Region , Month , Member ID , and Sales (with multiple transactions per member). I just want to extract the top 2 members, based on sum of sales, per region, per month....so essentially: Region Month MemberID Sales ----------------------------------------- 1 1/1/2013 A $200 2 2/1/2013 B $300 1 1/1/2013 A $100 1 1/1/2013 B $50 2 1/1/2013 D $500 2 2/1/2013 C $200 Becomes: Region Month Member ID Sales -------------------

SQLzoo JOIN tutorial #13

五迷三道 提交于 2021-02-18 16:53:17
问题 I have been working on the SQLzoo problems but having trouble with the last one in the JOIN tutorial question #13 - List every match with the goals scored by each team as shown. Link: http://sqlzoo.net/wiki/The_JOIN_operation In the sample code they gave, it uses a case. I modified it like this: SELECT game.mdate, game.team1, CASE WHEN goal.teamid=game.team1 THEN 1 ELSE 0 END score1, game.team2, CASE WHEN goal.teamid=game.team2 THEN 1 ELSE 0 END score2 FROM game, goal WHERE game.id=goal