Is this possible? MS Access query selecting a field to be on top and others will be in alpha order - ms-access-2010

Example i have a table:
----------------------
ID. | Color
----------------------
A1. | Red
A2. | Yellow
A3. | Blue
A4. | Black
-----------------------
Is this possible to sort a table like this? specify a field to be on top (example: Yellow) then the other records will be in alphabetical order.
the Color field can only be sorted.
----------------------
ID. | Color
----------------------
A2. | Yellow
A4. | Black
A3. | Blue
A1. | Red
-----------------------
Is there a query related to this? Thanks.

You can use:
Select
ID,
Color
From
YourTable
Order By
Abs([Color] = "Yellow") Desc,
Color Asc

select *
from something
order by
case when Color = "Yellow" then "1"
else Color
end

Related

Keep NA values in ggplot2 in R

I thought this would be easy ... but couldn't find a solution.
I am trying to generate a ggplot2 in R with correlation between col1 and col2, and size of the dot with col3, and shape with col4. col3 and col4 has NA/missing values. When running the code below, ggplot2 removes the rows without a matching col3 and/or col4, however, I want to keep these and color code. Output below
Example dataframe:
Warning:
Removed 3 rows containing missing values (geom_point).
I tried to create another geom_point with is.na(df$col3 | df$col4) but that wouldn't work.
tried adding na.rm=FALSE in
geom_point(aes(size=df$col3, col=df$col4), na.rm=FALSE)
tried
scale_size(range = c(0.25,4), na.value = 0) #to give a 0 value to the na.value (although would rather not)
But, I ended with "Ignoring unknown aesthetics: na.rm" for #2 and #3, and #1 gave an error.
Also, that doesn't fix the issue that col4 shapes are being removed too
ggplot(df, aes(x=df$col1, y=df$col2)) +
geom_point(aes(size=df$col3, col=df$col4), na.rm=FALSE) +
theme_classic() +
scale_size(range = c(0.25,4))
+-------------+-------------+-------------+----------+
| col1 | col2 | col3 | col4 |
+-------------+-------------+-------------+----------+
| 0.254393811 | 0.124242905 | NA | NA |
| 0.28223149 | 0.148601748 | 0.236953099 | CD8CTL |
| 0.205945835 | 0.074541695 | NA | NA |
| 0.199758631 | 0.103369485 | NA | CD8Mem |
| 0.2798128 | 0.109511863 | 0.396113132 | CD8STAT1 |
| 0.254616042 | 0.059495241 | 0.479590212 | CD8CTL |
| 0.197929395 | 0.10993698 | 0.272611442 | CD8CTL |
| 0.294888359 | 0.12319682 | 0.16069263 | CD8CTL |
| 0.191407446 | 0.086443936 | 0.36596486 | CD8CTL |
| 0.267533392 | 0.11240525 | 0.344659516 | CD8CTL |
+-------------+-------------+-------------+----------+
There's a few things to note - I think I have understood what the OP is looking to do here. In this case, you want all points to plot. I'm going to state how we want the plot to look:
col1 is used to plot x axis
col2 is used to plot y axis
col3 is used to control the size of the point
col4 is used to control the color of the point
We have NA values in col3 and col4. So what to do with those? Well, for color, I'm going to have those labeled and include them in the legend color-coded and labeled as "NA". What about for size? Well, size=NA doesn't make any sense, so I think the best thing to do for df$col3 == NA is going to be to change the shape. Here's what I've done:
ggplot(df, aes(x=col1, y=col2, color=col4)) +
geom_point(aes(size=col3, shape='Not NA')) +
geom_point(data=subset(df, is.na(col3)), aes(shape='NA'), size=3) +
scale_shape_manual(values=c('NA'=3, 'Not NA'=19)) +
theme_classic()
First of all, it's bad form to reference columns via data.frame$column.name - you should use just the column name itself.
Color is easy - we just put color=col4 in the top aes() specification, since it's applied to every geom.
For the shape, it's probably easiest here to specify in two separate calls to geom_point(). One is without any specification, which will naturally remove any NAs - you won't get points plotted with size=NA. To "add back in" the NA points, we have to specifically pull those out and specify a size. Finally, in order to get the shape aesthetic inside a legend, we need to put it inside the aes(). The general rule here is that if you set an aesthetic equal to the column name inside aes(), it will use the values inside that column for labelling. If you just type a character inside aes() like we did here, you will have all items in that geom call labeled with that character - but the legend is created. So, we basically are creating our own custom legend for shape here.
Then it's just a matter of using scale_shape_manual() and a named vector for the values argument to set the actual shape we want to use.
EDIT
Thinking about this a bit more, it doesn't make sense for NA to appear in the legend for color and shape, so let's remove it from color. That's done by completely separating the dataset that includes NAs in col3 from the one that doesn't:
ggplot(df, aes(x=col1, y=col2, color=col4)) +
geom_point(data=subset(df, !is.na(col3)), aes(size=col3, shape='Not NA')) +
geom_point(data=subset(df, is.na(col3)), aes(shape='NA'), size=3) +
scale_shape_manual(values=c('NA'=3, 'Not NA'=19)) +
theme_classic()
Please take a look to the following links:
http://naniar.njtierney.com/reference/geom_miss_point.html
Plotting missing values in ggplot2 with a separate line type
By the way, your explanation is clear on what you are trying to achieve. I see that the problem will be related to which shape and color to use when there is no value in Col3 and Col4. Maybe try solving it like this, like
When NAN in Col3 and Col4, color and shape is this for Col1 and Col2 correlation.
Another test would be to use geom_miss_point

DynamoDB Table/Index Modeling + Querying

Basic requirements:
I have a table with a bunch of attributes (20-30), but only 3 are used in querying: User, Category, and Date, and would be structured something like this...
User | Category | Date | ...
1 | Red | 5/15
1 | Green | 5/15
1 | Red | 5/16
1 | Green | 5/16
2 | Red | 5/18
2 | Green | 5/18
I want to be able to query this table in the following 2 ways:
Most recent rows (based on Date) by User. e.g., User=1 returns the 2 rows from 5/16 (3rd and 4th row)
Most recent rows (based on Date) by User and Category. e.g., User=1, Category=Red returns the 5/16 row only (the 3rd row).
Is the best way to model this with a HASH on User, RANGE on Date, and a GSI with HASH on User+Category and RANGE on Date? Is there anything else that might be more efficient? If that's the path of least resistance, I'd still need to know how many rows to return, which would require doing a count against distinct categories or something?
I've decided that it's going to be easier to just change the way I'm storing the documents. I'll move the category and other attributes into a sub-document so I can easily query against User+Date and I'll do any User+Category+Date querying with some client-side code against the User+Date result set.

Filter on a Query Item

I am creating a report and have a field that has multiple values representing different data values. i.e 4-Completeness 5-accuracy etc... What I need to do is make multiple columns where that field is filtered down to one value. The problem is I get the error if I try and edit the query item in the report of 'Boolen value expression as query item is not supported' How do I fix?
example:
ID column | Data Value = 4 | Actual Data | Data Value = 5
EDIT:
I currently have a case when [Data value] = 4 then [percentage] for the different columns but I am still getting wrong output. I am getting
ID1 | 45% | | |
ID1 | | 35% | |
ID1 | | | 67% |
I need all of ID1 to be in one row.
You can fix this by totaling by ID which will combine all three rows in your example to one:
total([Measure] for [ID])
Change each of the three percentage columns to use this expression, substituting their respective data item for [Measure].
Normally, you don't want to total percentages, but this is an exception. Since only one row has actual data, the total will match that row and the other two null values will not be included in the total.
Simple way would be to do it for each data value in three queries and join them on ID1

Selenium IDE, identify row in table based on 3 columns

I am trying to find a row in a table which contains specific values on three columns.
I have tried methods in #paul trmbrth's answer to find XPath to identify cell in table based on other column. Worked fine for 2 columns, but didn't worked with 3. I didn't find any example for cases with more than 2 values.
VEHICLE CATEGORY | CATEGORY | SUBCATEGORY
A | Exteriors | Badges
A | Exteriors | Badges
A | Exteriors | Mirrors
A | Interiors | Wheels
A | Interiors | Rears
Want cell with the combination that contains:
A | Exteriors | Mirrors
I have tried but no success:
//tr[contains(td[1], 'A')]/td[2][contains(., 'Exterior')] td[3][contains(., 'Mirror')]
//tr[contains(td[1], 'A')]/td[2][contains(., 'Exterior')] /td[3][contains(., 'Mirror')]
css=tr([td:contains('A')][td:contains('Exterior')][td:contains('Mirror')])
css=tr([td:contains('A')][td:contains('Exterior')][td:contains('Mirror')])
Can anyone help?
I think you have a couple of typos:
//tr[contains(td[1], '1') and contains(td[2], 'Eve') and contains(td[3], 'Jackson')]
But I'm not 100% this is most efficient, but it will work.

How to find Nth percentile with SQLite?

I'll like to find Nth percentile.
for example: table: htwt; columns: name, gender, height, weight
result:
| gender | 90% height | 90% weight |
| male | 190 | 90 |
| female | 180 | 80 |
sqlite is not strong in analytical processing but if your data is not very large, you can try to emulate percentile with ORDER BY, LIMIT 1 and a calculated OFFSET. Note that OFFSET is zero-based so you need to adjust it by one.
SELECT
height AS 'male 90% height'
FROM table
WHERE gender='male'
ORDER BY height ASC
LIMIT 1
OFFSET (SELECT
COUNT(*)
FROM table
WHERE gender='male') * 9 / 10 - 1;
I needed multiple percentages (10, 20 ... 100%) and solved it with:
WITH p AS (SELECT height, NTILE(10) OVER (ORDER BY height) AS percentile
FROM table
WHERE gender = 'male')
SELECT percentile, MAX(height) as height
FROM p
GROUP BY percentile;
This solution requires SQLite 3.28.0 or later for the NTILE window function.

Resources