sql

How do I use another column if two rows in the first column checked are the same?

て烟熏妆下的殇ゞ 提交于 2021-02-15 07:48:28
问题 I have a table that looks something like this: stones ID number snumber wt qt 1 a 11.5 13 2 c 4.0 8 3 a a1 1.0 2 4 d 0.5 1 5 b 2.0 4 6 a a2 5.0 1 7 f 3.0 6 8 a a3 5.0 10 How do I select all from stones and if the column number has rows in the column snumber only give results from snumber 's rows [otherwise use number ]? I am also trying to incorporate in my previous [working] code that selects all rows in the table that wt >= 2.5 then count all those rows as totalrows : SELECT inv.*, COUNT(*)

How do I use another column if two rows in the first column checked are the same?

时间秒杀一切 提交于 2021-02-15 07:48:23
问题 I have a table that looks something like this: stones ID number snumber wt qt 1 a 11.5 13 2 c 4.0 8 3 a a1 1.0 2 4 d 0.5 1 5 b 2.0 4 6 a a2 5.0 1 7 f 3.0 6 8 a a3 5.0 10 How do I select all from stones and if the column number has rows in the column snumber only give results from snumber 's rows [otherwise use number ]? I am also trying to incorporate in my previous [working] code that selects all rows in the table that wt >= 2.5 then count all those rows as totalrows : SELECT inv.*, COUNT(*)

Join by nearest date for the table with duplicate records in BigQuery

Deadly 提交于 2021-02-15 07:48:19
问题 I have installs table with installs that have the same user_id but different install_date . I want to get all revenue records joined with nearest install record by install_date that is less then revenue_date because I need it's source field value for next processing. That means that output rows count should be equal to revenue table records. How can it be achieved in BigQuery? Here is the data: installs install_date user_id source -------------------------------- 2020-01-10 user_a source_I

count records in ms access using query

血红的双手。 提交于 2021-02-15 07:45:05
问题 how to count record in ms access? here are my tables [basicinfo](table1) [Name age rawscore](fields) mark 16 6 paul 17 5 bryan 16 8 jenny 16 7 verbal(table2) [rawscore scaledscore](fields) 1 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 writen(table3) [rawscore scaledscore]fields 1 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 basically i want to count how many examinee has a scaled score of 1,2,3,4,5 both for table 2 and 3 回答1: Try the following query. It will list each scaled score and a count of

SQL Server Dynamic pivot for an unknow number of columns

▼魔方 西西 提交于 2021-02-15 07:44:29
问题 The question has been asked before, but in a slightly different scenario (one that doesn't seem to fit to my question) so.. I have data that looks like this Name |Item |Note George|Paperclip |Two boxes George|Stapler |blue one George|Stapler |red one George|Desk lamp |No light bulb Mark |Paperclip |One box 2" Mark |Paperclip |One box 4" Mark |Block Notes|a blue one ..? |..? |..? And I would want to pivot by name, to obtain Name |Paperclip|Stapler|Desk Lamp|Block Notes George| 1| 2| 1| NULL

count records in ms access using query

你离开我真会死。 提交于 2021-02-15 07:43:49
问题 how to count record in ms access? here are my tables [basicinfo](table1) [Name age rawscore](fields) mark 16 6 paul 17 5 bryan 16 8 jenny 16 7 verbal(table2) [rawscore scaledscore](fields) 1 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 writen(table3) [rawscore scaledscore]fields 1 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 basically i want to count how many examinee has a scaled score of 1,2,3,4,5 both for table 2 and 3 回答1: Try the following query. It will list each scaled score and a count of

How to convert SQL Unpivot query to HANA SQL?

匆匆过客 提交于 2021-02-15 07:43:43
问题 How to convert following SQL Server query which uses unpivot to a HANA SQL query. SELECT p.CardName, REPLACE(p.groupcode1, 'QryGroup', '') groupcode1, ocqg.GroupName FROM ocrd UNPIVOT (value FOR groupcode1 IN ([QryGroup1], [QryGroup2], [QryGroup3], [QryGroup4], [QryGroup5], [QryGroup6], [QryGroup7], [QryGroup8], [QryGroup9], [QryGroup10], [QryGroup11], [QryGroup12], [QryGroup13], [QryGroup14], [QryGroup15],[QryGroup16], [QryGroup17], [QryGroup18], [QryGroup19],[QryGroup20], [QryGroup21],

SQLLite strftime not reading column value

烈酒焚心 提交于 2021-02-15 07:42:14
问题 i have this in my Sqllite Database query, i want ... select BoardingDate, strftime('%Y', date(BoardingDate)) from Hostels; but in the output it renders BoardingDate correctly and the output BoardingDate Month ------------------------- 8/1/2007 0:00:00 null 3/1/2008 0:00:00 null 8/1/2008 0:00:00 null 3/1/2009 0:00:00 null These is the current behaviour of the queries 1. strftime('%Y', date('now')) - outputs correctly 2. strftime('%Y', date('2020-03-06')) - it works also 3. strftime('%Y', date

How to convert “2019-11-02T20:18:00Z” to timestamp in HQL?

拟墨画扇 提交于 2021-02-15 07:28:06
问题 I have datetime string "2019-11-02T20:18:00Z" . How can I convert it into timestamp in Hive HQL? 回答1: If you want preserve milliseconds then remove Z , replace T with space and convert to timestamp: select timestamp(regexp_replace("2019-11-02T20:18:00Z", '^(.+?)T(.+?)Z$','$1 $2')); Result: 2019-11-02 20:18:00 Also it works with milliseconds: select timestamp(regexp_replace("2019-11-02T20:18:00.123Z", '^(.+?)T(.+?)Z$','$1 $2')); Result: 2019-11-02 20:18:00.123 Using from_unixtime(unix

Cross Join in Entity framework Lambda Expressions

半城伤御伤魂 提交于 2021-02-15 06:58:02
问题 How can I do the following join in EF? Tables have no relation with each other, no foreign keys. Select t1.ID, t1.firstname, t2.ID,t2.name from MY_TEST_TABLE1 t1, MY_TEST_TABLE2 t2 where t1.firstname = t2.name 回答1: You could do this: var query= from t1 in context.MY_TEST_TABLE1 from t2 in context.MY_TEST_TABLE2 where t1.firstname == t2.name select new { Table1Id= t1.ID, FirstName= t1.firstname, Table2Id=t2.ID,Name= t2.name}; Another way to do a cross join in Linq to Entities is using